Skip to content
This repository

pylab doesn't work in qtconsole #1043

miham opened this Issue November 25, 2011 · 6 comments

4 participants

Miha Marolt Thomas Kluyver Matthias Bussonnier Jens H Nielsen
Miha Marolt

I pulled the latest version of ipython from github and ran

miha:ipython(master)$ python2 qtconsole --profile=pylab &
[1] 23979
miha:ipython(master)$ [IPythonQtConsoleApp] Staging bundled
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/<ipython-input-1-f7c53b90cc25> in <module>()
----> 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 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 -- 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/<ipython-input-1-9f297ed2f0c6> in <module>()
      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/ in <module>()
     94 from matplotlib.backends import pylab_setup
---> 95 new_figure_manager, draw_if_interactive, _show = pylab_setup()
     97 @docstring.copy_dedent(Artist.findobj)

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

/usr/lib/python2.7/site-packages/matplotlib/backends/ in
     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/ in <module>()
     19     import qt
     20 except ImportError:
---> 21     raise ImportError("Qt backend requires pyqt to be installed.")
     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.

Matthias Bussonnier

I think I came across the same issues on one of my computer, I was to blame, but I can't try for now

qtagg means qt3 , you can see that that it tries to import qt and not qt4
could you try matplotlib.use('qt4agg') (note the '4')

Thomas Kluyver

Note that the normal way to start pylab is with --pylab, not --profile=pylab. I don't know why the latter works in the terminal but not the Qt console.

Jens H Nielsen

I can confirm that this happens when running ipython qtconsole --profile=pylab
However it works fine when running it like ipython qtconsole --pylab=qt
Also pasting the above lines into a regular ipython qtconsole without pylab activated seems to work fine.
Tested on ubuntu 11.10

Thomas Kluyver

I think we should be calling use('qt4agg') rather than with qtagg (which seems to mean Qt 3). For some reason, the terminal seems to ignore that change.

Miha Marolt

qtagg means qt3 , you can see that that it tries to import qt and not qt4
could you try matplotlib.use('qt4agg') (note the '4')

When I change qtagg to qt4agg in the profile, pylab works even if started with python2 qtconsole --profile=pylab.

And it works even without the change if i start qtconsole with python2 qtconsole --pylab like takluyver suggested.


Thomas Kluyver

OK, great, I've changed the default config file to use qt4agg.

Thomas Kluyver takluyver closed this November 25, 2011
Brian E. Granger ellisonbg referenced this issue from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.