Linux Python 2.7 无法导入 PyQt4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4010842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 2.7 cannot import PyQt4
提问by Austin Adams
I've upgraded to Python 2.7 from Python 2.6 on Ubuntu Maverick Meerkat (10.10) and I'm unable to import PyQt4.
我已在 Ubuntu Maverick Meerkat (10.10) 上从 Python 2.6 升级到 Python 2.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
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.
我从 Ubuntu 存储库安装了 Python 2.7 (python2.7) 和 PyQt4 (python-qt4)。不久前我安装了 PyQt,但最近我安装了 Python 2.7。
If I try Python 2.6 (since it's shipped with Ubuntu, the command is simply python), it works perfectly. Watch:
如果我尝试使用 Python 2.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
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!
我知道问题是什么:Python 2.6 可以访问 PyQt4 模块,但不能通过 2.7 访问。我的问题是,如何让 Python 2.7 找到 PyQt4 模块?帮助!
Note: sorry if this belongs in Super User, I was just programming when I encountered this problem.
注意:对不起,如果这属于超级用户,我遇到这个问题时只是在编程。
采纳答案by shane
Under Ubuntu system, you could install it via apt-get
在Ubuntu系统下,可以通过apt-get安装
apt-get install python-qt4
回答by EMP
You should install PyQt4 in the Python 2.7 environment. To do this run
您应该在 Python 2.7 环境中安装 PyQt4。要执行此运行
easy_install2.7 PyQt4
If easy_install is not installed you will need to first download and install it by running
如果未安装easy_install,您需要先下载并运行以下命令安装它
python2.7 setup.py install
回答by karolx
As PyQt is not using setup.py it cannot be installed using pip or easy_install
由于 PyQt 不使用 setup.py,因此无法使用 pip 或 easy_install 进行安装
Here you have a tutorial showing how to build and install PyQt for python2.7:
这里有一个教程,展示了如何为 python2.7 构建和安装 PyQt:
http://problemssol.blogspot.com/2010/12/compile-and-install-pyqt4-for-python27.html
http://problemssol.blogspot.com/2010/12/compile-and-install-pyqt4-for-python27.html
Update:For Ubuntu 12.04+ just use apt-get:
更新:对于 Ubuntu 12.04+,只需使用 apt-get:
apt-get install python-qt4
回答by Hui
Please install SIP module first,this is python and c/c++ lib tools, and PyQt4 lib
请先安装SIP模块,这是python和c/c++库工具,以及PyQt4库
回答by TONy.W
OSX 10.8.2 tested:
OSX 10.8.2 测试:
sudo pip install SIP
got IOError: [Errno 2] No such file or directory: '/tmp/pip-build/SIP/setup.py'
得到 IOError: [Errno 2] 没有这样的文件或目录:'/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
从以下位置下载 PyQt: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:
需要一段时间,然后在 make 之后:
sudo make install
Enjoy it :)
好好享受 :)
回答by Sol
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:
您可以在此处为任何版本的 Python 下载任何版本的 PyQt4,但由于您要求的是 python 2.7,这里是 python 2.7 的下载链接:
https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/
https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/