PyCharm中import matplotlib包时报错“Backend Qt5Agg is interactive backend”

在PyCharm使用Python Console导入matplotlib.pyplot时遇到'Backend Qt5Agg is interactive backend'错误,可通过更新matplotlib库、修改matplotlibrc文件,将后端从Qt5Agg改为TkAgg,或者调整交互模式设置来解决。具体操作包括修改matplotlibrc文件中的backend和interactive选项,然后重启PyCharm。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在PyCharm的Python Console中 import matplotlib.pyplot as plt 时,会出现Backend Qt5Agg is interactive backend. Turning interactive mode on. 或者其他跟Qt5Agg相关的错误,导致程序中断。

虽然现在还不得而知Qt5Agg的问题如何解决,但是一种可以绕过这种问题(我的环境是:PyCharm 2017.2.3、PyQt5 5.9、 PyQt4 4.11.4、matplotlib 2.1.0、 ipython 5.3.0、Anaconda3、Python 3.6.0 )。

首先可以简单的更新一下自己的环境的库,比如matplotlib,确保是的自己的matplotlib中含有TkAgg。使用命令conda update matplotlib修改matplotlibrc 文件。该文件的位置在C:\ProgramData\Anaconda3\pkgs\matplotlib-2.1.0-py36h11b4b9c_0\Lib\site-packages 。打开该文件后,在大概30行的地方会看到如下的文本。将Qt5Agg 修改为 TkAgg ,并保存。

# The default backend; one of GTK GTKAgg GTKCairo GTK3Agg GTK3Cairo
# MacOSX Qt4Agg Qt5Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG
# Template.
# You can also deploy your own backend outside of matplotlib by
# referring to the module name (which must be in the PYTHONPATH) as
# 'module://my_backend'.
#
# If you omit this parameter, it will always default to "Agg", which is a
# non-interactive backend.
# backend      : Qt5Agg  # original
backend      : TkAgg  # new

如果想在import matplotlib.pylab as plt 时,不出现Backend Qt5Agg is interactive backend. Turning interactive mode on. ,可以修改上述文件中大致73行,将#interactive : False 修改为interactive : True 保存即可。然后重启PyCharm,此时import matplotlib.pylab as plt 时,正常运行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值