PyCharm和ipython的组合无法导入qt5或Qt5Agg

时间:2016-10-08 16:46:05

标签: python matplotlib pyqt ipython pycharm

我已经通过conda安装了基本的os和Pycharm以及整个python堆栈,现在在ipython sesssion中启动交互式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时,不会发生此问题。另外,如果我在导入matplotlib.use('Qt5Agg')之前pyplot,则错误会在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教育3.0没有帮助

我怎样才能让它发挥作用?

3 个答案:

答案 0 :(得分:8)

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

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

conda install pyqt=4.11.4 

答案 1 :(得分:0)

作为替代方案,您可以按照http://matplotlib.org/users/customizing.html

中的报告配置matplotlibrc 在Linux上

该文件应该放在.config / matplotlib / matplotlibrc

刚设置:

backend      : qt4Agg

这解决了我的问题。

答案 2 :(得分:0)

select to_char( start_of_week, 'day dd.mm.yyyy' ) start_of_week, to_char( start_of_week + 6, 'day dd.mm.yyyy' ) end_of_week from ( select trunc( date '2017-01-01' + 38*7 , 'day') start_of_week from dual ) 中将D:\PyCharm Community Edition 2016.1.4\helpers\pydev\_pydev_bundle\pydev_ipython_console_011.py的默认值从gui更改为None

qt4