Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up IPython Qtconsole with PyQt5

On an OSX 10.9, I have Qt5 installed. Later I installed Ipython, sip and PyQt5 all build from source. Now here is the problem: when I try to run ipython qtconsole, I have a bunch of errors related to the files in this directory (and its subfolders)

/Library/Python/2.7/site-packages/IPython/

followed by

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

   Currently-imported Qt library:   None
   PyQt4 installed:                 False
   PySide >= 1.0.3 installed:       False
   Tried to load:                   ['pyside', 'pyqt']

I assume the problem is that I have PyQt5 instead of PyQt4. Is this the problem or I have missed some thing else?

Is there anyway that I can have qtconsole with PyQt5? If no, what is the easiest way to do so? (preferably, a method that does not involve having two versions of Qt library on one machine).


For sake of brevity I skipped posting the full error message. Please let me know if I should add them from better understanding of the situation.

like image 286
Pouya Avatar asked Jun 20 '14 09:06

Pouya


People also ask

Is PyQt4 compatible with PyQt5?

PyQt5 is not compatibile with PyQt4 (although experience shows that the effort in porting applications from PyQt4 to PyQt5 is not great).

What is Qtconsole in Anaconda?

anaconda / packages / qtconsole 1. 0 The Qt console is a very lightweight application that largely feels like a terminal, but provides a number of enhancements only possible in a GUI, such as inline figures, proper multiline editing with syntax highlighting, graphical calltips, and more.


4 Answers

The problem might be related to your python path.

I had almost the exact same problem. I had installed PyQt using Homebrew and I was getting the same error message. Finally what solved the problem was adding the following line to my .bash_profile:

export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

Since I am a beginner myself, I can't help you any further but I hope this solves the problem.

like image 100
oxtay Avatar answered Oct 20 '22 07:10

oxtay


I know this is really old, but I was recently having trouble setting up PyQt5.

The problem was that PyQt5 would install, but some of the sub modules would not. For instance try

import PyQt5 #works
from PyQt5 import * # might fail

If the second command fails, then you have a problem with the PyQt5 setup, and you need to focus on that.

Specifically, ipython+qt will try to import the following

from PyQt5 import QtCore, QtSvg, QtWidgets, QtGui

If any of these sub-modules are broken/missing the qt console launch will quietly fail.

For me it turned out that the PyQt5 installer was failing to make the QtSvg bindings, which ipython tries to load from PyQt5. When you run the configure.py, use the -w option and you will see all the details of the build, allowing you to pinpoint where the install is failing.

In my case, a little googling and I found out that I was missing the QtSvg lib, which can be pulled in easily from the repos.

like image 23
dermen Avatar answered Oct 20 '22 05:10

dermen


Setting environment variable QT_API=pyqt5 solved the same problem for me.

like image 24
vvch Avatar answered Oct 20 '22 07:10

vvch


I had the same problem, though with the most recent brew of ipython the ImportError included PyQt5 (along with PyQt4 and PySide). So if it didn't work with PyQt5 before, it does now.

Adding the correct PYTHONPATH to .bash_profile fixed it for me, even in my virtualenv. (I don't have the reputation to up-vote or comment on oxtay's answer, where this would be more appropriate...)

like image 30
Cody Avatar answered Oct 20 '22 07:10

Cody