开发者

Python 2.7 cannot import PyQt4

I've upgraded to Python 2.7 from Python 2.6 on Ubuntu Maverick Meerkat (10.10) and I'm unable to import PyQt4.

austin@gerald:~$ python2.7
Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4

I installed both Python 2.7 (python2.7) and PyQt4 (python-qt4) from the Ubuntu repositories. I installed PyQt a while back, but I installed Python 2.7 recently.

If I try Python 2.6 (since it's shipped with Ubuntu, the command is simply python), it works perfectly. Watch:

austin@gerald:~$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4

I know what the problem is: the PyQt4 modules are accessible by Python 2.6 but not 2.7. My question is, how do I get Python 2.7 to find the PyQt4 module(s)? Help!

Note: sorry if this belongs in Super User, I was just programming when I encountered th开发者_如何学Pythonis problem.


As PyQt is not using setup.py it cannot be installed using pip or easy_install

Here you have a tutorial showing how to build and install PyQt for python2.7:

http://problemssol.blogspot.com/2010/12/compile-and-install-pyqt4-for-python27.html

Update: For Ubuntu 12.04+ just use apt-get:

apt-get install python-qt4


Under Ubuntu system, you could install it via apt-get

apt-get install python-qt4


OSX 10.8.2 tested:

sudo pip install SIP

got IOError: [Errno 2] No such file or directory: '/tmp/pip-build/SIP/setup.py'

It's ok then:

cd /tmp/pip-build/SIP
sudo python configure.py
make
sudo make install

download PyQt from: http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.9.6/PyQt-mac-gpl-4.9.6.tar.gz

unzip it.

cd PyQt-mac-gpl-4.9.6
sudo python configure.py
make

it will take a while, after make then:

sudo make install    

Enjoy it :)


You can download any version of PyQt4 here for any version of Python but since you asked for python 2.7, Here is the link for the download for python 2.7:

https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/


You should install PyQt4 in the Python 2.7 environment. To do this run

easy_install2.7 PyQt4

If easy_install is not installed you will need to first download and install it by running

python2.7 setup.py install


Please install SIP module first,this is python and c/c++ lib tools, and PyQt4 lib

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜