Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pylab doesn't work in qtconsole #1043

Closed
miham opened this issue Nov 25, 2011 · 6 comments
Closed

pylab doesn't work in qtconsole #1043

miham opened this issue Nov 25, 2011 · 6 comments

Comments

@miham
Copy link

miham commented Nov 25, 2011

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
Copy link
Member

Carreau commented Nov 25, 2011

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
Copy link
Member

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
Copy link
Contributor

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
Copy link
Member

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
Copy link
Author

miham commented Nov 25, 2011

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
Copy link
Member

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

stefanv pushed a commit to stefanv/ipython that referenced this issue Nov 30, 2011
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants