You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Jupyter Notebook中使用Julia Plots绘图失败求助

Julia Jupyter Notebook中Plots绘图报错:找不到临时SVG文件(Windows 10)

问题场景

在Julia REPL中可正常使用Plots绘图,但在Jupyter Notebook运行以下基础代码时:

using Plots
x = 1:10; y = rand(10); # These are the plotting data
plot(x, y)

出现错误:

SystemError: opening file "C:\Users\Kasia\AppData\Local\Temp\jl_rgpMDkxG5u.svg": No such file or directory

已尝试卸载重装Plots、更新Plots和GR,问题仍未解决。

解决方案

  • 手动指定GR后端临时文件路径
    系统临时目录权限问题或GR的临时文件生成逻辑在Jupyter环境下异常时,可手动指定一个用户有权限的目录:

    using Plots, GR
    GR.inline("svg")
    # 用用户目录下的GR_Temp文件夹存储临时文件
    temp_dir = joinpath(homedir(), "GR_Temp")
    isdir(temp_dir) || mkdir(temp_dir)
    ENV["GRDIR"] = temp_dir
    plot(1:10, rand(10))
    
  • 检查临时目录权限
    确认当前用户对C:\Users\Kasia\AppData\Local\Temp文件夹有读写权限:右键该文件夹→属性→安全选项卡,确保当前用户账户拥有「读取」「写入」权限。若权限不足,添加对应权限后重启Jupyter再测试。

  • 切换Plots后端
    若GR后端问题无法解决,尝试切换到其他后端:

    • PyPlot后端:
      using Pkg
      Pkg.add("PyPlot")
      using Plots
      pyplot()
      plot(1:10, rand(10))
      
    • Plotly后端:
      using Pkg
      Pkg.add("Plotly")
      using Plots
      plotly()
      plot(1:10, rand(10))
      
  • 重置Julia包环境
    清理旧的包缓存并重新构建:

    using Pkg
    Pkg.rm(["Plots", "GR"])
    Pkg.gc() # 清理无用包文件
    Pkg.add(["Plots", "GR"])
    Pkg.build(["Plots", "GR"])
    

    完成后关闭并重启Jupyter Notebook,再运行绘图代码测试。

内容的提问来源于stack exchange,提问作者Kat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 06:20:28