Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Here's pycharm's 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

And here is what happens if I try to import 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. When I don't select ipython, however, I only get an irresponsive black screen when I plt.figure().
  • This problem does not happen when I start ipython manually from the terminal (outside of pycharm). 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.
  • Installing on a new conda environment following conda create -n test python=3.5 ; conda install ipython matplotlib scipy -n test and loading the new environment in pycharm did not help
  • Reinstalling pycharm 2.3 or Invalidate Caches + Restart did not help
  • Installing pycharm educational 3.0 did not help

How can I get this to work?

like image 888
FooBar Avatar asked Oct 08 '16 16:10

FooBar


1 Answers

Pycharm appears to not fully support qt5, the issue is open. Downgrading it is the fastest workaround.

With conda the following will perform a downgrade to the last stable version:

conda install pyqt=4.11.4 
like image 98
FooBar Avatar answered Nov 05 '22 19:11

FooBar