Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Ubuntu中为Python 3配置PyQt4?_Ubuntu_Python 3.x_Pyqt - Fatal编程技术网

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

如何在Ubuntu中为Python 3配置PyQt4?,ubuntu,python-3.x,pyqt,Ubuntu,Python 3.x,Pyqt,这个问题最初是在askubuntu.com上提出来的,但没有引起注意,所以我想也许这是一个更好的问题 我用synaptic安装了PyQt4 我使用的是Python3,所以我需要在eclipse中配置PyQt4的路径,但synaptic似乎只为Python2安装了PyQt4,因为我只在Python2.6和2.7下找到了相关文件和文件夹 那么,如何使PyQt4与Python3和eclipse一起工作呢 谢谢 更新: 我尝试在以下帖子中对其进行配置: 但是,在按照所有指令进行操作而没有出现任何错误后,

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

我用synaptic安装了PyQt4

我使用的是Python3,所以我需要在eclipse中配置PyQt4的路径,但synaptic似乎只为Python2安装了PyQt4,因为我只在Python2.6和2.7下找到了相关文件和文件夹

那么,如何使PyQt4与Python3和eclipse一起工作呢

谢谢

更新

我尝试在以下帖子中对其进行配置:

但是,在按照所有指令进行操作而没有出现任何错误后,在python 3.2中运行此代码时会出现错误:

>>> import PyQt4
错误消息是:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为PyQt4的模块

但奇怪的是,相同的代码在python2.7中没有产生错误(我的机器上安装了2.7和3.2)

看起来ubuntu只有python2的pyqt4包,因此您必须为python3编译单独的pyqt4

通过查看每个python的
站点包
目录,可以检查您已经安装的内容。要查找这些目录,请运行:

python2.7 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
python3.2 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
如果pyqt安装正确,则在
站点包
下应有一个
PyQt4
目录,其中包含几十个
*。因此
文件

据推测,python3.2将没有任何内容,这就是为什么您不能导入pyqt

要为python3.2安装pyqt,请执行以下操作。请注意,使用正确的python配置构建非常重要,例如:

/usr/bin/python3.2 configure.py

安装编译所需的软件包(我不确定是否需要这些):

下载最新SIP的源代码-(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的源代码-(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的python3版本。打开终端并键入:

sudo apt-get install python3-pyqt4
这样,您就不必从源代码编译Qt4。我也测试过这个,pyqt4可以与python3一起工作

资料来源:
快速搜索ubuntu存储库。

我在帖子中提到的帖子比你提到的说明更详细,我还使用python 3.2运行configure.py。但是它仍然不能正常工作。pyqt libs是否安装在python3.2的
站点包
目录中?不,它不在那里,这就是问题所在。在/usr/lib/pyshared/python2.7/PyQt4和/usr/lib/python2.7/dist-packages/PyQt4下都有*.so文件。只需将这些文件复制到python3.2的文件夹就可以解决这个问题吗?@SpiritZhang。您给出的两条路径都适用于python2.7。不要移动或复制这些目录中的任何文件。听起来您已经构建并安装了
sip
,但您还没有构建并安装pyqt本身。请注意,您链接到的说明实际上并不包括构建和安装pyqt的说明,但我的答案中的链接确实包含。在做任何其他事情之前,请仔细阅读这些说明,并确保您理解您需要做什么。如果您有什么不明白的,请询问。看起来PyQt4 for Python3的包在Ubuntu 12.10的repos中更好!截至2015年2月,我注意到还有
python3-pyqt5
可用。真不敢相信我花了多长时间才找到这个。我为没有检查正式的repos firsterror感到羞愧:仍然缺少必需的依赖项“pyqt4 dbus(PyQt 4 dbus-pyqt4的dbus支持)”。对我来说不起作用。仍然找不到模块PyQT4:(@nauticalfile)您需要确保启用了[universe]存储库。
sudo apt-get install python3-pyqt4