Setting up IPython Qtconsole with PyQt5

六眼飞鱼酱① 提交于 2019-12-01 01:12:04

问题


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.


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/24324621/setting-up-ipython-qtconsole-with-pyqt5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!