在Ubuntu 14.04 64bit上安装python-pyqt5软件包(python 2.7)

分类: linux |
一、摘要
Python-pyqt5
pyqt5
http://www.riverbankcomputing.com/software/pyqt/download5
下载安装即可。安装的过程很漫长,繁杂,特将踩坑过程记录出来。另外,这可能是目前为止网上最好的一篇pyqt5的安装笔记,比其它同类安装过程都简洁。
二、简介
PyQt是Qt库在Python的绑定版本,PyQt为我们Python程序员提供了使用完整Qt应用程序接口,几乎可以用Python做任何C++能做的事。作为一种编程语言,python相对于c++的优点是在编程效率上。
PyQt(Python的GUI模块)既成熟又稳定,并且有庞大用户的群体,我从用户那儿得到的两个最普通的反馈是它恰到好处和它很简单易用。
PyQt
PyQt5支持Python
配置PyQt5之前,必须首先安装SIP。
三、安装
1.安装QT库(含QT4和QT5)
sudo apt-get install qt-sdk
下载的软件包很大
如果自己编译QT库,那就需要手动修改路径
cd /usr/lib/x86_64-Linux-gnu/qt-default/qtchooser/
会有一个default.conf配置文件,可以修改默认配置文件为你编译好的QT库路径
http://img.blog.csdn.net/20150615074224244?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
http://img.blog.csdn.net/20150615074243461?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
2.安装SIP
从官网
http://www.riverbankcomputing.com/software/sip/download
下载最新稳定的tar.gz源码包,当前版本是sip-4.16.8.tar.gz,并解压
http://img.blog.csdn.net/20150615073951301?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
http://img.blog.csdn.net/20150615074025779?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
3.安装PyQt5
建议从官网
http://www.riverbankcomputing.com/software/pyqt/download5
下载源码包,不要从github上
https://github.com/baoboa/pyqt5
下载源码,因为编译有问题,参见遇到的问题4.
解压源码后,进入源码目录,运行
python
make
-j4
sudo
make
编译过程很漫长,我的顶配ThinkPad T420温度飙到80+度,持续十多分钟。
http://img.blog.csdn.net/20150615072845533?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
http://img.blog.csdn.net/20150615073743465?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
http://img.blog.csdn.net/20150615073657270?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
http://img.blog.csdn.net/20150615072714997?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
http://img.blog.csdn.net/20150615074349745?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
出错原因,没有安装qt4库,执行
sudo apt-get install qt-sdk
问题2
Error: Make sure you have a working sip on your PATH or use the --sip argument to explicitly specify a working sip.
http://img.blog.csdn.net/20150615073849173?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
问题3
sipAPIQtCore.h:28:17: fatal error: sip.h: 没有那个文件或目录
http://img.blog.csdn.net/20150615072946715?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
参考链接
https://shenwang.blog.ustc.edu.cn/huhamhire-hosts/
问题4
qpyopengl_add_constants.o:在函数‘qpyopengl_add_constants(_object*)’中:
qpyopengl_add_constants.cpp:(.text+0x0): `qpyopengl_add_constants(_object*)'被多次定义
qpyopengl_add_constants.o:qpyopengl_add_constants.cpp:(.text+0x0):第一次在此定义
collect2: error: ld returned 1 exit status
make[1]: *** [libQtGui.so] 错误 1
make[1]:正在离开目录 `/home/taoyx/program_develop/pyqt5/QtGui'
http://img.blog.csdn.net/20150615072819980?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
仔细研究发现该QtGui目录下有两个同名文件并且实现代码完全相同, 不同之处仅是:
qpyopengl_add_constants.cpp,使用defined(SIP_FEATURE_PyQt_OpenGL)控制
qpyopengl_add_constants.c 没有使用宏控制
问题应该是禁用该宏才不会导致该问题
先验证PyQt4和PyQt5模块是否能成功加载?
http://img.blog.csdn.net/20150617085540559?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFvXzYyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center14.04
- #!/usr/bin/env
python - #encoding:
utf-8 -
- import
sys - from
PyQt5 importQtCore, QtGui, QtWidgets -
- if
__name__ '__main__':== -
app = QtWidgets.QApplication(sys.argv) -
w = QtWidgets.QWidget() -
w.resize(250, 150) -
w.move(300, 300) -
w.setWindowTitle('helloworld') -
w.show() -
sys.exit(app.exec_())
运行效果截图
六、参考文献
Error: PyQt5 requires Qt v5.0 or later
When I come back to run the command above, I get the same error:
However, after Qt5 installation, when
I run this: I get this:
|
Error: Make sure you have a working sip on your PATH or use the --sip argument to explicitly specify a working sip
begueradj@begueradj-hacker:~/Bureau/PyQt-gpl-5.4.1# python configure.py
Querying qmake about your Qt installation...
Determining the details of your Qt installation...
This is the GPL version of PyQt 5.4.1 (licensed under the GNU General Public
License) for Python 2.7.6 on linux2.
Type 'L' to view the 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.
Error: Make sure you have a working sip on your PATH or use the --sip argument
to explicitly specify a working sip.
1
2
3
4
5
6
7
8
9
10
11
|
you need to install sip
first (not just configure it) begueradj
@begueradj :~/Bureau/sip-4.16.7 #
python configure.py begueradj
@begueradj :~/Bureau/sip-4.16.7 #
make begueradj
@begueradj :~/Bureau/sip-4.16.7 #
make install and
next you can install PyQt : begueradj
@begueradj :~/Bureau/PyQt-gpl-5.4.1
# python configure-ng.py begueradj
@begueradj :~/Bureau/PyQt-gpl-5.4.1
# python configure-ng.py --sip /usr/bin/sip |
In file included from greenlet.c:5:0:
greenlet.h:8:20: 致命错误: Python.h:没有那个文件或目录
编译中断。
error: Setup script exited
with error: command 'gcc' failed with exit status
1
解决方法是安装python-dev,这是Python的头文件和静态库包:
sudo apt-get install python-dev