PyCharm远程解释器(2019.1)+ Matplotlib导入错误

时间:2019-05-22 10:41:48

标签: python matplotlib pyqt pycharm

在使用Python 3.6构建新的conda环境后,PyQt5(pyqt == 5.6.0)从PyCharm(2019.1。版)初始化时遇到问题。

ssh -Y放入框中后,可以从iPython shell构建绘图。

但是从PyCharm导入matplotlib会引发以下错误:

import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "/share/dir/python/conda-env-py36/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3296, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-a0d2faabd9e9>", line 1, in <module>
    import matplotlib.pyplot as plt
  File "/home/user/.pycharm_helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 20, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/share/dir/python/conda-env-py36/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2609, in <module>
    install_repl_displayhook()
  File "/share/dir/python/conda-env-py36/lib/python3.6/site-packages/matplotlib/pyplot.py", line 166, in install_repl_displayhook
    ip.enable_gui(ipython_gui_name)
  File "/home/user/.pycharm_helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 130, in enable_gui
    return real_enable_gui(gui, app)
  File "/home/user/.pycharm_helpers/pydev/pydev_ipython/inputhook.py", line 536, in enable_gui
    return gui_hook(app)
  File "/home/user/.pycharm_helpers/pydev/pydev_ipython/inputhook.py", line 174, in enable_qt
    from pydev_ipython.qt_for_kernel import QT_API, QT_API_PYQT5
  File "/home/user/.pycharm_helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 20, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/user/.pycharm_helpers/pydev/pydev_ipython/qt_for_kernel.py", line 115, in <module>
    QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts)
  File "/home/user/.pycharm_helpers/pydev/pydev_ipython/qt_loaders.py", line 258, in load_qt
    if not can_import(api):
  File "/home/user/.pycharm_helpers/pydev/pydev_ipython/qt_loaders.py", line 146, in can_import
    if not has_binding(api):
  File "/home/user/.pycharm_helpers/pydev/pydev_ipython/qt_loaders.py", line 114, in has_binding
    imp.find_module('QtCore', mod.__path__)
  File "/share/dir/python/conda-env-py36/lib/python3.6/imp.py", line 270, in find_module
    "not {}".format(type(path)))
RuntimeError: 'path' must be None or a list, not <class '_frozen_importlib_external._NamespacePath'>

跟随stacktrace并查看相关文件会使我相信这与conda安装或conda env中的软件包的PyCharm识别有关。

使用PyCharm的Matplotlib 2.2.2运行基于PyQt5的绘图时,是否还有其他人遇到过问题?

2 个答案:

答案 0 :(得分:0)

在安装pyqt时,我使用了conda。运行conda install时,PyQt软件包似乎已链接,而不是复制到环境中。链接显然不符合预期。

我通过指定--copy解决了这个问题。有关详情,请参见conda docs。这是完整的安装命令:

conda install pyqt==5.6.0 --copy

答案 1 :(得分:0)

对我来说,问题是我通过pip安装了pyqt5,而pyqt已经通过conda安装了。 运行:

conda remove pyqt
conda install matplotlib