我已经通过 conda
安装了 elementary os 和 Pycharm 以及整个 python 堆栈,现在在 ipython
session 中启动交互式 matplotlib 时遇到问题。
这是 pycharm 的 ipython session :
/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 环境中安装; conda install ipython matplotlib scipy -n test
并在 pycharm 中加载新环境没有帮助 - 重新安装 pycharm 2.3 或使缓存无效 + 重新启动没有帮助
- 安装pycharm educational 3.0没有帮助
我怎样才能让它工作?
最佳答案
关于python - PyCharm 和 ipython 的组合无法导入 qt5 或 Qt5Agg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39934861/