在Ubuntu 11.04和Python 2.7+中安装PyQt4时出错

2 投票
2 回答
4795 浏览
提问于 2025-04-17 08:48
>>> from PyQt4.QtCore import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4.QtCore

我一直在尝试安装 PyQt4.QtWebKit,但遇到了一些问题。我按照这些 说明进行了操作。

我可以顺利地安装 SIP(执行 ./configure、make 和 make install),但在安装 PyQt 时却遇到了麻烦。

出现的错误是:

ubuntu@ip-10-32-157-231:~/Desktop/build/PyQt$ sudo python configure.py --verbose -q     /usr/bin/qmake
Determining the layout of your Qt installation...
/usr/bin/qmake -o qtdirs.mk qtdirs.pro
make -f qtdirs.mk
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -o qtdirs.o qtdirs.cpp
qtdirs.cpp:1:28: fatal error: QCoreApplication: No such file or directory
compilation terminated.
make: *** [qtdirs.o] Error 1
Error: Failed to determine the layout of your Qt installation. Try again using
the --verbose flag to see more detail about the problem.
ubuntu@ip-10-32-157-231:~/Desktop/build/PyQt$

你能给我建议一下,如何在 ubuntu natty(11.04)和 python 2.7+ 上成功安装 PyQt4 吗?

2 个回答

1

这个“教程”真是太糟糕了,会把你的系统搞得一团糟。可惜我也跟着做了,因为我对压缩包和构建不成功感到很沮丧(我当时不知道它已经在Ubuntu的仓库里了)。

无论如何,只需在终端里运行这段代码:

sudo apt-get purge python-qt4 python-sip
sudo apt-get install python-qt4 python-sip

这样应该就能解决问题。如果你愿意,也可以在Synaptic里做这个……

5

你跟着的那些步骤其实是错误的,容易让人误解。

在ubuntu 11.04上,你不需要自己去搭建什么,因为它已经包含了所有需要的包。

我建议你把按照那些步骤做的改动都撤回,然后重新开始。

要安装一个基本的PyQt4,只需要安装以下这些包:

(当然,还要安装任何依赖包)。

撰写回答