ImportError:没有名为PyQt5的模块

时间:2018-11-28 22:27:59

标签: python matplotlib anaconda

当我尝试在Windows 10的Windows X64计算机上导入在命令窗口中运行的Python 2.7的Anaconda发行版的matplotlib.pyplot时,出现此错误。我可以从Jupyter笔记本中导入模块。有解决办法吗?

整个回溯是:

C:\Users\You>python
Python 2.7.14 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:34:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\pyplot.py", line 113, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\backends\__init__.py", line 60, in pylab_setup
    [backend_name], 0)
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 16, in <module>
    from .backend_qt5 import (
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\backends\backend_qt5.py", line 18, in <module>
    import matplotlib.backends.qt_editor.figureoptions as figureoptions
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\backends\qt_editor\figureoptions.py", line 20, in <module>
    import matplotlib.backends.qt_editor.formlayout as formlayout
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\backends\qt_editor\formlayout.py", line 56, in <module>
    from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\backends\qt_compat.py", line 137, in <module>
    from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: No module named PyQt5

1 个答案:

答案 0 :(得分:1)

如评论中所述,您必须先导入matplotlib,更改后端,然后再导入pyplot。

>>> import matplotlib
>>> matplotlib.use('Qt4Agg')
>>> import matplotlib.pyplot