Python 2.7无法导入PyQt4

2024-05-21 16:42:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经在UbuntuMaverickMeerkat(10.10)上从Python2.6升级到Python2.7,并且无法导入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

我从Ubuntu存储库安装了python2.7和PyQt4。我刚才安装了PyQt,但最近安装了Python 2.7。

如果我尝试使用Python2.6(因为它是随Ubuntu一起提供的,所以命令很简单Python),那么它工作得很好。观看:

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

我知道问题是什么:Python 2.6可以访问PyQt4模块,而不是2.7。我的问题是,如何让Python 2.7找到PyQt4模块?救命啊!

注意:很抱歉,如果这属于超级用户,我只是在编程时遇到这个问题。


Tags: orforlicenseonmoretypehelpsep
3条回答

由于PyQt没有使用setup.py,因此不能使用pip或easy_install安装它

这里有一个教程,演示如何为python2.7构建和安装PyQt:

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

更新: 对于Ubuntu 12.04+只需使用apt-get:

apt-get install python-qt4

在Ubuntu系统下,可以通过apt-get安装

apt-get install python-qt4

OSX 10.8.2测试:

sudo pip install SIP

得到IOError:[Errno 2]没有这样的文件或目录:'/tmp/pip build/SIP/setup.py'

那没关系:

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

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

把它解开。

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

需要一段时间,在制作之后:

sudo make install    

享受吧:)

相关问题 更多 >