问题描述
我在 Windows 10 机器上使用 Anaconda 和 Python 3.5.2、Matplotlib 2.0.2、PyQt5.6.当我将matplotlib.pyplot导入为plt时,出现以下错误:
I am using Anaconda with Python 3.5.2, Matplotlib 2.0.2, PyQt5.6 on a windows 10 machine. When I import matplotlib.pyplot as plt I get the following error:
...
File "C:...\Anaconda3\Lib\site-packages\matplotlib\backends\qt_compat.py",
line 137, in <module> from PyQt4 import QtCore, QtGui
ImportError: No module named 'PyQt4'
我的机器上从未安装过 PyQt4,我不知道为什么它要从 PyQt4 导入.
I don't know why it would want to import from PyQt4 when it has never been installed on my machine.
此问题具有相同的错误,但在实际具有PyQt4的计算机上安装.
This question has the same error, but on a machine that actually has PyQt4 installed.
我已经检查了matplotlibrc文件,在程序中使用了 matplotlib.use('qt5agg')
,还 matplotlib.rcParams ['backend'] ="Qt5Agg"
.我已经卸载并重新安装了上述所有软件包都无济于事.我什至试图安装 PyQt4 只是为了让事情顺利进行.我完全被难住了.我在 SO 或 github 上找到的各种可能的原因或补救措施都没有帮助.
I have checked my matplotlibrc file, I've used matplotlib.use('qt5agg')
in the program, also matplotlib.rcParams['backend'] = "Qt5Agg"
. I've uninstalled and reinstalled all the above packages to no avail. I have even attempted to install PyQt4 just to get things going. I'm completely stumped. None of the various possible causes or remedies that I've been able to find on either SO or github have helped.
推荐答案
貌似API版本是PyQt5但默认是PyQt4,打开工具->首选项->IPython控制台->图形->后端,把QT4改成QT5
It seems the API version is PyQt5 but the default is PyQt4,just open Tools -> Preferences -> IPython console -> Graphics -> backend,change QT4 to QT5
这篇关于PyQt5 得到“没有名为‘PyQt4’的模块";在 Python 3.5 中调用 matplotlib.pyplot 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!