Configuring Qtconsole IPython with PyQt5

On OSX 10.9, I have Qt5 installed. Later, I installed Ipython, sip, and PyQt5 to build from the source. Now here is the problem: when I try to start ipython qtconsole , I have a bunch of errors related to 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 PyQt5 has PyQt4 instead. Is this a problem, or am I missing something else?

Anyway, can I have qtconsole with PyQt5? If not, what is the easiest way to do this? (preferably, a method that does not require two versions of the Qt library on the same machine).


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

+6
source share
4 answers

The problem may be related to your python path.

I had almost the same problem. I installed PyQt using Homebrew and I got the same error message. Finally, the solution to this problem was to add the following line to my .bash_profile :

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

As I begin, I cannot help you, but I hope this solves the problem.

+3
source

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

+1
source

I had the same problem, though with the latest brew of ipython ImportError included (along with PyQt4 and PySide ). Therefore, if he had not worked with PyQt5 before, he does it now.

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

+1
source

I know this is really old, but I recently had a problem setting up PyQt5.

The problem was that PyQt5 would be installed, but some of the submodules would not. For example, try

 import PyQt5 #works from PyQt5 import * # might fail 

If the second command fails, you will have a problem setting up PyQt5, and you need to focus on that.

In particular, ipython + qt will try to import the following

 from PyQt5 import QtCore, QtSvg, QtWidgets, QtGui 

If any of these submodules is broken / missing, starting the qt console will be no problem .

For me, it turned out that the PyQt5 installer was unable to complete the QtSvg bindings that ipython is trying to download from PyQt5. When you run configure.py , use the -w option and you will see all the details of the assembly, allowing you to pinpoint where the installation fails.

In my case, a little googling, and I found out that I lack QtSvg lib , which can be easily extracted from repositories.

+1
source

Source: https://habr.com/ru/post/971091/


All Articles