本文介绍了VSCode无法切换matplotlib后端:ImportError:无法加载需要"qt5"交互式框架的后端"Qt5Agg"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想通过在VSCode中运行Python进行绘图,但结果却失败了.我无法将后端从 agg 切换到 Qt5Agg.但是,我可以在VSCode之外的终端中轻松地做到这一点...

I just want to plot by running Python in VSCode but in turn out failure. I cannot switch the backend from agg to Qt5Agg. However, I can easily do so in the terminal out of VSCode...

下面显示了VSCode集成终端中的问题,我在其中尝试了各种解决方案,但失败了..

The problem in VSCode integrated terminal is shown below, where I have tried various solutions but failed..:

(base) user@user:~/test$ export MPLBACKEND=Qt5Agg
(base) user@user:~/test$ python
Python 3.8.3 (default, Jul  2 2020, 16:21:59) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "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
>>> 

任何帮助将不胜感激.!!

Any help will be really appreciated. !!

推荐答案

我遇到了同样的问题.改变"terminal.integrated.inheritEnv".在设置中为true解决了问题.我不知道为什么,还没有遇到任何副作用.

I had the same problem. Changing "terminal.integrated.inheritEnv" to true in settings solved the problem. I don't know why and have not yet met any side effects.

这篇关于VSCode无法切换matplotlib后端:ImportError:无法加载需要"qt5"交互式框架的后端"Qt5Agg"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 17:48