Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

pylab doesn't work in qtconsole #1043

Closed
miham opened this Issue · 6 comments

4 participants

@miham

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/<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 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/<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/pyplot.py in <module>()
     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
<module>()
     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 <module>()
     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.

@Carreau
Owner

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')

@takluyver
Owner

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.

@jenshnielsen

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

@takluyver
Owner

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.

@miham

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 ipython.py qtconsole --profile=pylab.

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

Tnx.

@takluyver
Owner

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

@takluyver takluyver closed this
@stefanv stefanv referenced this issue from a commit in stefanv/ipython
@takluyver takluyver Use qt4agg, not qtagg, mpl backend in pylab profile.
Closes gh-1043
0adc60e
@ellisonbg ellisonbg referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@mattvonrocketstein mattvonrocketstein referenced this issue from a commit in mattvonrocketstein/ipython
@takluyver takluyver Use qt4agg, not qtagg, mpl backend in pylab profile.
Closes gh-1043
aa93c46
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.