I am using Python 3 on my ubuntu 14.04.2 (trusty), along with Python 2. I am trying to run ipython --pylab, but with Python 3, this fails (works well with Python 2). It fails since it needs QT4/5 or PySide.

I could not install PySide, but I could easily install PyQt4 with

sudo aptitude install python3-pyqt4 python3-pyqt5

However, that doesn't seem to do the job. The output of ipython --pylab is

ImportError: cannot import name 'QtCore'

matplotlib throws that error after trying to import QtCore from PyQt5. Funny thing, it fails exactly there even if PyQt5 is purged (but with the error No module namedPyQt5`)

Is there anything wrong with either matplotlib or with the python3-pyqt4/5 packages? Is it possible that python-pyqt4/5 do not even support python3.4?


After purging python3-pyqt4 and python3-pyqt5 and installing python3-pyside instead, ipython worked well with pylab. This is documented in the SO question I was linking to.

Now, with pyside installed, I have installed python3-pyqt5 again in order to answer a question from the comments, and now QtCore is properly imported (both in python and in ipython), but pylab is not working again.

The error is, however, much different:

    Could not load requested Qt binding. Please ensure that
    PyQt4 >= 4.7, PyQt5 or PySide >= 1.0.3 is available,
    and only one is imported per session.

    Currently-imported Qt library:   'pyqt5'
    PyQt4 installed:                 False
    PyQt5 installed:                 False
    PySide >= 1.0.3 installed:       True
    Tried to load:                   ['pyqt5']

Now, typing %pylab again from within the ipython console works. This is a very weird behaviour.

Update (2)

It seems that pyside, without the ubuntu package python3-pyqt5, does not really work. I can run ipython --pylab with no errors that way, but when I try to plot() or to scatter(), it fails with

AttributeError: 'figure()' is not a Qt property or a signal

So, it seems the only way I can make pylab work properly, it to install both python3-pyside and python3-pyqt5, see the weird ImportError quoted above, trying %pylab again, and work.

  • 1
    Can you run from PyQt5 import QtCore in the standard Python shell (python and python3) instead of IPython? – Eric Carvalho Aug 14 '15 at 11:20
  • I'm confused - are you invoking ipython as ipython or ipython3? – steeldriver Aug 14 '15 at 11:36
  • @EricCarvalho, updated my question. steeldriver, on my machine ipython is ipython3. – Bach Aug 14 '15 at 12:22
  • Installing python packages from the Ubuntu repository usually gives you antique software. Install the latest stable version from PyPI using the pip/pip3 command: sudo pip3 install PyQt5 or whichever package you want. It's also a good idea to upgrade pip itself first: sudo pip3 install --upgrade pip. Maybe you should run this upgrade command for all packages you need and have problems with. – Byte Commander Aug 14 '15 at 12:24
  • @ByteCommander, there is no pip package PyQt5. There is a package python-qt5, but it seems to be for Windows only. – Bach Aug 14 '15 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.