问题描述
这个问题最初是在askubuntu.com上提出的,但是没有引起注意,所以我认为这也许是一个更好的提出问题的地方。
我安装了带有突触的PyQt4。
我正在使用Python3,因此我需要在Eclipse中配置PyQt4的路径,但似乎突触只为python 2安装了PyQt4,因为我只在python 2.6和2.7下找到了相关文件和文件夹。
那么如何使PyQt4与Python 3和eclipse一起使用呢?
谢谢。
更新:
我在这篇文章之后尝试配置它:http://ubuntuforums.org/showthread.php?p=10914908#post10914908
但是在按照所有说明进行操作而没有任何错误之后,我在python 3.2中运行此代码时遇到错误:
>>> import PyQt4
错误消息是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4
但是奇怪的是,相同的代码在python 2.7中没有错误(我的机器上同时安装了2.7和3.2)
最佳办法
安装编译所需的软件包(我不确定是否都需要这些软件包):
sudo apt install build-essential python3-dev libqt4-dev
下载最新SIP的源-sip-4.12.4.tar.gz(Linux,UNIX,MacOS /X源)。
解压它们并进入目录:
vic@wic:~/Desktop/sip-4.12.4$ python3 configure.py
This is SIP 4.12.4 for Python 3.2 on linux2.
The SIP code generator will be installed in /usr/bin.
...
Creating sip module Makefile...
vic@wic:~/Desktop/sip-4.12.4$ make
make[1]: Entering directory `/home/vic/Desktop/sip-4.12.4/sipgen'
...
make[1]: Leaving directory `/home/vic/Desktop/sip-4.12.4/siplib'
vic@wic:~/Desktop/sip-4.12.4$ sudo make install
make[1]: Entering directory `/home/vic/Desktop/sip-4.12.4/sipgen'
...
cp -f /home/vic/Desktop/sip-4.12.4/sipdistutils.py /usr/lib/python3/dist-packages/sipdistutils.py
vic@wic:~/Desktop/sip-4.12.4$
下载最新的PyQt的源-PyQt-x11-gpl-4.8.5.tar.gz(Linux,UNIX源),并安装它:
vic@wic:~/Desktop/PyQt-x11-gpl-4.8.5$ python3 configure.py
Determining the layout of your Qt installation...
This is the GPL version of PyQt 4.8.5 (licensed under the GNU General Public License) for Python 3.2 on linux2.
Type '2' to view the GPL v2 license.
Type '3' to view the GPL v3 license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.
Do you accept the terms of the license? yes
Found the license file pyqt-gpl.sip.
Checking to see if the QtGui module should be built...
...
Checking to see if the dbus support module should be built...
The Python dbus module doesn't seem to be installed.
Qt v4.7.2 free edition is being used.
SIP 4.12.4 is being used.
The Qt header files are in /usr/include/qt4.
...
Creating pyqtconfig.py...
vic@wic:~/Desktop/PyQt-x11-gpl-4.8.5$ make
make[1]: Entering directory `/home/vic/Desktop/PyQt-x11-gpl-4.8.5/qpy'
...
make[1]: Leaving directory `/home/vic/Desktop/PyQt-x11-gpl-4.8.5/designer'
vic@wic:~/Desktop/PyQt-x11-gpl-4.8.5$ sudo make install
make[1]: Entering directory `/home/vic/Desktop/PyQt-x11-gpl-4.8.5/qpy'
...
cp -f PyQt4.api /usr/share/qt4/qsci/api/python/PyQt4.api
请注意,我正在启动python3
而不是python
。
次佳办法
您应该能够在ubuntu中安装PyQt4的python 3版本。打开一个终端并输入:
sudo apt-get install python3-pyqt4
这样,您不必从源代码编译Qt4。我也对此进行了测试,并且pyqt4可与python3一起使用。
来源:在ubuntu存储库中快速搜索。