简体   繁体   English

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

[英]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
  • This problem only happens when ipython is installed. 只有在安装ipythonipython此问题。 When I don't select ipython, however, I only get an irresponsive black screen when I plt.figure() . 但是,当我没有选择ipython时,我只能在plt.figure()时得到一个plt.figure()
  • This problem does not happen when I start 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控制台中。
  • Installing on a new conda environment following 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中加载新环境没有帮助
  • Reinstalling pycharm 2.3 or Invalidate Caches + Restart did not help 重新安装pycharm 2.3或Invalidate Caches + Restart没有帮助
  • Installing pycharm educational 3.0 did not help 安装pycharm教育3.0没有帮助

How can I get this to work? 我怎样才能让它发挥作用?

Pycharm appears to not fully support qt5 , the issue is open . Pycharm似乎不完全支持qt5 ,问题是开放的 Downgrading it is the fastest workaround. 降级它是最快的解决方法。

With conda the following will perform a downgrade to the last stable version: 使用conda,以下将执行降级到最后一个稳定版本:

conda install pyqt=4.11.4 

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.

相关问题 无法加载需要“qt5”交互框架的后端“Qt5Agg”,因为“headless”当前正在运行 - Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework, as 'headless' is currently running Matplotlib 未找到 Qt5Agg 后端 - Matplotlib Qt5Agg backend not found VSCode 无法切换 matplotlib 后端:ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework - VSCode cannot switch matplotlib backend: ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework 如何将 matplotlib 中的默认后端从“QtAgg”更改为 Pycharm 中的“Qt5Agg”? - How to change the default backend in matplotlib from 'QtAgg' to 'Qt5Agg' in Pycharm? 具有Qt5Agg后端的matplotlib返回空的ticklabels - matplotlib with Qt5Agg backend returns empty ticklabels 无法使用 Qt5Agg 后端渲染 matplotlib 图 - Can't render a matplotlib graph using Qt5Agg backend 在4K屏幕上使用Matplotlib和TKAgg或Qt5Agg后端 - Using Matplotlib with TKAgg or Qt5Agg backend on 4K screen 调试:matplotlib.pyplot:加载后端 qt5agg 版本未知 - DEBUG:matplotlib.pyplot:Loaded backend qt5agg version unknown Matplotlib Funcanimation 在 Qt5Agg 后端调整 window 大小时恢复循环 - Matplotlib Funcanimation resumes loop upon window resizing in Qt5Agg backend PyCharm 无法调试 Qt5 (PySide2) 代码 - 错误'Shiboken.ObjectType' object 不可迭代 - PyCharm fails to debug Qt5 (PySide2) code - Error 'Shiboken.ObjectType' object is not iterable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM