如何在Ubuntu中为Python 3配置PyQt4?

Der*_*ang 28 ubuntu pyqt python-3.x

这个问题最初是在askubuntu.com上提出的,但没有引起注意,所以我想也许这是一个更好的问题.

我用synaptic安装了PyQt4.

我正在使用Python3所以我需要在eclipse中配置PyQt4的路径,但似乎synaptic只为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
Run Code Online (Sandbox Code Playgroud)

错误消息是:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4
Run Code Online (Sandbox Code Playgroud)

但奇怪的是,相同的代码在python 2.7中导致NO错误(我的机器上安装了2.7和3.2)

小智 66

您应该能够在ubuntu中安装python 3版本的PyQt4.打开终端并输入:

sudo apt-get install python3-pyqt4
Run Code Online (Sandbox Code Playgroud)

这样您就不必从源代码编译Qt4.我也测试了这个,pyqt4与python3一起使用.

来源:在ubuntu存储库中快速搜索.

  • 好多了!截至2015年2月,我注意到`python3-pyqt5`也可用. (8认同)
  • 不适合我。仍然找不到模块 PyQT4 :( (2认同)

war*_*iuc 30

安装编译所需的包(我不确定这些都是必需的):

sudo apt install build-essential python3-dev libqt4-dev
Run Code Online (Sandbox Code Playgroud)

下载最新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$
Run Code Online (Sandbox Code Playgroud)

下载最新的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
Run Code Online (Sandbox Code Playgroud)

请注意,我正在启动python3而不是python.