我只想通過在 VSCode 中運行 Python 進行繪圖,但結果失敗了。我無法將后端從 agg 切換到 Qt5Agg。但是,我可以在 VSCode 的終端中輕松地這樣做......VSCode集成終端的問題如下圖,我嘗試了各種解決方案都失敗了..:(base) user@user:~/test$ export MPLBACKEND=Qt5Agg(base) user@user:~/test$ pythonPython 3.8.3 (default, Jul 2 2020, 16:21:59) [GCC 7.3.0] :: Anaconda, Inc. on linuxType "help", "copyright", "credits" or "license" for more information.>>> import matplotlib>>> print("Using:",matplotlib.get_backend())Using: Qt5Agg>>> import matplotlib.pyplot as plt>>> plt.plot([1,2,3], [10, 20, 30])[<matplotlib.lines.Line2D object at 0x7fe26b403d00>]>>> plt.show()>>> print("Using:",matplotlib.get_backend())Using: agg>>> plt.switch_backend('Qt5Agg')Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/zslwyuan-laptop/anaconda3/lib/python3.8/site-packages/matplotlib-3.3.0rc1+627.gff821ba32-py3.8-linux-x86_64.egg/matplotlib/pyplot.py", line 268, in switch_backend raise ImportError(ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework, as 'headless' is currently running>>> 任何幫助將不勝感激。!!
1 回答

茅侃侃
TA貢獻1842條經驗 獲得超21個贊
我有同樣的問題。在設置中將“terminal.integrated.inheritEnv”更改為 true 解決了這個問題。我不知道為什么,還沒有遇到任何副作用。
添加回答
舉報
0/150
提交
取消