【问题标题】:Combination of PyCharm and ipython fails to import qt5 or Qt5AggPyCharm和ipython结合导入qt5或Qt5Agg失败
【发布时间】:2017-02-17 11:49:59
【问题描述】:

我已经通过conda 安装了elementary os 和Pycharm 以及整个python 堆栈,现在在ipython 会话中启动交互式matplotlib 时遇到了麻烦。

这里是 pycharm 的 ipython 会话:

/home/foo/.conda/envs/myenv3/bin/python3.5 /opt/pycharm-2016.2.3/helpers/pydev/pydevconsole.py 41070 33134
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:53:06) 
Type "copyright", "credits" or "license" for more information.

IPython 5.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
PyDev console: using IPython 5.0.0

import sys; print('Python %s on %s' % (sys.version, sys.platform))

Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux

如果我尝试导入 pyplot,会发生以下情况:

In[4]: import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "/opt/pycharm-2016.2.3/helpers/pydev/pydev_ipython/inputhook.py", line 502, in enable_gui
    gui_hook = guis[gui]
KeyError: 'qt5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/pycharm-2016.2.3/helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 123, in enable_gui
    return real_enable_gui(gui, app)
  File "/opt/pycharm-2016.2.3/helpers/pydev/pydev_ipython/inputhook.py", line 508, in enable_gui
    raise ValueError(e)
ValueError: Invalid GUI request 'qt5', valid ones are:dict_keys(['gtk3', 'wx', 'qt', 'osx', 'pyglet', 'glut', 'tk', 'gtk', 'none', 'qt4'])

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/foo/.conda/envs/myenv3/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2869, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-4-eff513f636fd>", line 1, in <module>
    import matplotlib.pyplot as plt
  • 只有在安装了ipython 时才会出现此问题。 但是,当我不选择 ipython 时,我只会在plt.figure() 时出现无响应的黑屏
  • 当我从终端(pycharm 外部)手动启动ipython 时,不会发生此问题。另外,如果我在导入pyplot 之前执行matplotlib.use('Qt5Agg'),则错误仍然存​​在于pycharm 中,但不会出现在我终端的ipython 控制台中。
  • conda create -n test python=3.5 ; conda install ipython matplotlib scipy -n test 之后在新的 conda 环境中安装并在 pycharm 中加载新环境没有帮助
  • 重新安装 pycharm 2.3 或 Invalidate Caches + Restart 没有帮助
  • 安装 pycharm Education 3.0 没有帮助

我怎样才能让它工作?

【问题讨论】:

    标签: python matplotlib pyqt ipython pycharm


    【解决方案1】:

    Pycharm 似乎不完全支持qt5,问题是open。降级它是最快的解决方法。

    使用 conda,以下将执行降级到最后一个稳定版本:

    conda install pyqt=4.11.4 
    

    【讨论】:

      【解决方案2】:

      作为替代方案,您可以按照http://matplotlib.org/users/customizing.html 中的报告配置您的 matplotlibrc

      在 linux 上,文件应该放在 .config/matplotlib/matplotlibrc 中

      刚刚设置:

      backend      : qt4Agg
      

      这解决了我的问题。

      【讨论】:

        【解决方案3】:

        D:\PyCharm Community Edition 2016.1.4\helpers\pydev\_pydev_bundle\pydev_ipython_console_011.py 中,将gui 的默认值从None 更改为qt4

         # In the PyDev Console, GUI control is done via hookable XML-RPC server
        @staticmethod
        def enable_gui(gui=qt4, app=None):
            """Switch amongst GUI input hooks by name.
            """
        

        【讨论】:

          猜你喜欢
          • 2016-08-28
          • 1970-01-01
          • 2019-09-04
          • 2016-05-17
          • 2016-09-25
          • 1970-01-01
          • 1970-01-01
          • 2020-08-18
          • 1970-01-01
          相关资源
          最近更新 更多