jupyter / qtconsole

Jupyter Qt Console
https://qtconsole.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
417 stars 200 forks source link

IPython Matplotlib QT Backend RuntimeError #261

Open JesterEE opened 6 years ago

JesterEE commented 6 years ago

This issue was originally reported to the Spyder project with Issue #5989, but upon the recommendation of @CAM-Gerlach, it was found to be a QtConsole issue.

The issue reported here is much the same, but I updated it a little to just represent the process of recreating it in QtConsole.

When using the matplotlib QT5 graphics backend through IPython magic, the following error is generated:

get_ipython().run_line_magic('matplotlib', 'qt5')

Traceback (most recent call last):

  File "<ipython-input-1-64557277dbff>", line 1, in <module>
    get_ipython().run_line_magic('matplotlib', 'qt5')

  File "C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2095, in run_line_magic
    result = fn(*args,**kwargs)

  File "<decorator-gen-108>", line 2, in matplotlib

  File "C:\Anaconda3\lib\site-packages\IPython\core\magic.py", line 187, in <lambda>
    call = lambda f, *a, **k: f(*a, **k)

  File "C:\Anaconda3\lib\site-packages\IPython\core\magics\pylab.py", line 99, in matplotlib
    gui, backend = self.shell.enable_matplotlib(args.gui)

  File "C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2983, in enable_matplotlib
    self.enable_gui(gui)

  File "C:\Anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 482, in enable_gui
    real_enable_gui(gui)

  File "C:\Anaconda3\lib\site-packages\ipykernel\eventloops.py", line 337, in enable_gui
    raise RuntimeError("Cannot activate multiple GUI eventloops")

RuntimeError: Cannot activate multiple GUI eventloops

I tried running a similar set of commands in an IPython notebook (with Jupyter) and didn't receive this error:

import matplotlib.pyplot

%matplotlib qt5
matplotlib.pyplot.plot()

%matplotlib inline
matplotlib.pyplot.plot()

%matplotlib qt5
matplotlib.pyplot.plot()

Workaround If the backend is first set to inline and then set to qt, the error is not observed.

get_ipython().run_line_magic('matplotlib', 'inline')
get_ipython().run_line_magic('matplotlib', 'qt5')

Version and main components

Spyder Dependencies

pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.21.1 (OK)
numpy >=1.7      :  1.13.3 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
rope >=0.9.4     :  0.10.7 (OK)
jedi >=0.9.0     :  0.11.0 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.27.3 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.2.1 (OK)
pylint >=0.25    :  1.7.4 (OK)
astromancer commented 4 years ago

This no longer seems to be an issue for me on current master:

Screenshot from 2020-05-20 09-18-46