[英]Combination of PyCharm and ipython fails to import qt5 or Qt5Agg
I have installed elementary os and Pycharm and the whole python stack via conda
, and now have troubles starting interactive matplotlib in the ipython
sesssion. 我已经安装了基本的操作系统和Pycharm,并通过全蟒蛇栈conda
,现在都要开始在互动matplotlib烦恼ipython
sesssion。
Here's pycharm's ipython session: 这是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
And here is what happens if I try to import pyplot
: 如果我尝试导入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
is installed. 只有在安装ipython
时ipython
此问题。 When I don't select ipython, however, I only get an irresponsive black screen when I plt.figure()
. 但是,当我没有选择ipython时,我只能在plt.figure()
时得到一个plt.figure()
。 ipython
manually from the terminal (outside of pycharm). 当我从终端(pycharm之外)手动启动ipython
时,不会发生此问题。 Also, if I do matplotlib.use('Qt5Agg')
before importing pyplot
, the error persists in pycharm, but does not appear in the ipython console in my terminal. 此外,如果我在导入pyplot
之前执行matplotlib.use('Qt5Agg')
,则错误在pycharm中仍然存在,但不会出现在终端的ipython控制台中。 conda create -n test python=3.5 ; conda install ipython matplotlib scipy -n test
在conda之后安装新的conda环境conda create -n test python=3.5 ; conda install ipython matplotlib scipy -n test
conda create -n test python=3.5 ; conda install ipython matplotlib scipy -n test
and loading the new environment in pycharm did not help conda create -n test python=3.5 ; conda install ipython matplotlib scipy -n test
并在pycharm中加载新环境没有帮助 How can I get this to work? 我怎样才能让它发挥作用?
As an alternative you can configure your matplotlibrc as reported in http://matplotlib.org/users/customizing.html 作为替代方案,您可以按照http://matplotlib.org/users/customizing.html中的报告配置matplotlibrc。
on linux the file should go in .config/matplotlib/matplotlibrc 在linux上,该文件应该放在.config / matplotlib / matplotlibrc中
just set: 刚设置:
backend : qt4Agg
this solved my issue. 这解决了我的问题。
In D:\\PyCharm Community Edition 2016.1.4\\helpers\\pydev\\_pydev_bundle\\pydev_ipython_console_011.py
change the default value of gui
from None
to qt4
: 在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.
"""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.