VSCode cannot switch matplotlib backend: ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework

梦想的初衷 提交于 2020-12-06 13:27:06

问题


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...

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. !!


回答1:


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.



来源:https://stackoverflow.com/questions/63328024/vscode-cannot-switch-matplotlib-backend-importerror-cannot-load-backend-qt5ag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!