ipython/ipython — Issue #1043: pylab doesn't work in qtconsole
Author: miham
Created: 2011-11-25 11:08:36+00:00
State: open

I pulled the latest version of ipython from github and ran

miha:ipython(master)$ python2 ipython.py qtconsole --profile=pylab &
[1] 23979
miha:ipython(master)$ [IPythonQtConsoleApp] Staging bundled ipython_config.py
from pylab into u'/home/miha/.config/ipython/profile_pylab'
[IPKernelApp] To connect another client to this kernel, use:
[IPKernelApp] --existing kernel-23979.json --profile pylab
[IPythonQtConsoleApp] History request failed: {u'status': u'aborted'}
[IPythonQtConsoleApp] Retrying aborted history request

In qtconsole I tried to use pylab, but I got this errors:

In [1]: plt.plot((1,2,3))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/miha_shr/coding/repos/ipython/ in ()
----> 1 plt.plot((1,2,3))

NameError: name 'plt' is not defined

In [2]: matplotlib.__version__
Out[2]: '1.1.0'

The same commands work perfectly well in terminal mode. One gets a more
informative traceback if he manually pastes code from pylab profile into
qtconsole. So I run `$ python2 ipython.py qtconsole` and paste in the code:

Python 2.7.2 (default, Jun 29 2011, 11:10:00)
Type "copyright", "credits" or "license" for more information.

IPython 0.12.dev -- 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.
%guiref -> A brief reference about the graphical user interface.

In [1]: import matplotlib
...: %gui qt
...: matplotlib.use('qtagg')
...: matplotlib.interactive(True)
...: from matplotlib import pyplot as plt
...: from matplotlib.pyplot import *
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/miha_shr/coding/repos/ipython/ in ()
3 matplotlib.use('qtagg')
4 matplotlib.interactive(True)
----> 5 from matplotlib import pyplot as plt
6 from matplotlib.pyplot import *

/usr/lib/python2.7/site-packages/matplotlib/pyplot.py in ()
93
94 from matplotlib.backends import pylab_setup
---> 95 new_figure_manager, draw_if_interactive, _show = pylab_setup()
96
97 @docstring.copy_dedent(Artist.findobj)

/usr/lib/python2.7/site-packages/matplotlib/backends/__init__.pyc in
pylab_setup()
23 backend_name = 'matplotlib.backends.%s'%backend_name.lower()
24 backend_mod = __import__(backend_name,
---> 25 globals(),locals(),[backend_name])
26
27 # Things we pull in from all backends

/usr/lib/python2.7/site-packages/matplotlib/backends/backend_qtagg.py in
()
10
11 from backend_agg import FigureCanvasAgg
---> 12 from backend_qt import qt, FigureManagerQT, FigureCanvasQT,\
13 show, draw_if_interactive, backend_version, \
14 NavigationToolbar2QT

/usr/lib/python2.7/site-packages/matplotlib/backends/backend_qt.py in ()
19 import qt
20 except ImportError:
---> 21 raise ImportError("Qt backend requires pyqt to be installed.")
22
23 backend_version = "0.9.1"

ImportError: Qt backend requires pyqt to be installed.

But i DO have pyqt installed (version 4.8.6-1 in Arch Linux) and it works ok in
terminal mode.