zl程序教程

您现在的位置是:首页 >  其他

当前栏目

尝试安装PyQt

安装 尝试 Pyqt
2023-09-14 08:58:20 时间

我的系统是:Linux localhost.localdomain 2.6.32-358.23.2.el6.i686 #1 SMP Wed Oct 16 17:21:31 UTC 2013 i686 i686 i386 GNU/Linux

我之前有在系统上安装QtSDK-5.1.1与QtCreator-2.8.1


从官网上下载PyQt的源码:PyQt4 Download

官网上说:“Before you can build PyQt4 you must have already built and installed SIP” 意思是说必须先安装SIP,于是也下载了SIP。

解压SIP压缩包,进入源码目录,打开README,说是当前目录下有一个build.py,结果我没有找到。但找到了一个configure.py的代码。于是我执行它


$ python configure.py
正常完成,并生成了Makefile。我下意识地执行make,结果:


gcc -c -pipe -fPIC -O2 -w -DNDEBUG -I. -I/usr/include/python2.6 -o siplib.o siplib.c

siplib.c:20:20: fatal error: Python.h: No such file or directory

 #include Python.h 

compilation terminated.

make[1]: *** [siplib.o] Error 1

make[1]: Leaving directory `/home/hevake_lcj/Install/qt-downloads/sip-4.15.3/siplib

make: *** [all] Error 2
通常这种问题出在系统没有安装组件的开发板,只提供了库文件,并没有提供对应的头文件,不能进行二次开发。解决文件就是安装python-devel


$ sudo yum install python-devel
完成安装。再make,顺利通过编译。再sudo make install,也很顺利。测试是否完成安装:


$ sip -h

Usage:

 sip [-h] [-V] [-a file] [-b file] [-c dir] [-d file] [-e] [-g] [-I dir] [-j #] [-k] [-m file] [-o] [-p module] [-P] [-r] [-s suffix] [-t tag] [-T] [-w] [-x feature] [-X id:file] [-z file] [file]

where:

 -h display this help message

 -V display the sip version number

 -a file the name of the QScintilla API file [default not generated]

 -b file the name of the build file [default none generated]

 -c dir the name of the code directory [default not generated]

 -d file the name of the documentation file (deprecated) [default not generated]

 -e enable support for exceptions [default disabled]

 -g always release and reacquire the GIL [default only when specified]

 -I dir look in this directory when including files

 -j # split the generated code into # files [default 1 per class]

 -k support keyword arguments in functions and methods

 -m file the name of the XML export file [default not generated]

 -o enable the automatic generation of docstrings [default disabled]

 -p module the name of the consolidated module that this is a component of

 -P enable the protected/public hack

 -r generate code with tracing enabled [default disabled]

 -s suffix the suffix to use for C or C++ source files [default ".c" or ".cpp"]

 -t tag the version/platform to generate code for

 -T disable the timestamp in the header of generated files

 -w enable warning messages

 -x feature this feature is disabled

 -X id:file create the extracts for an id in a file

 -z file the name of a file containing more command line flags

 file the name of the specification file [default stdin]

安装OK。


解压下载的:PyQt-x11-gpl-4.10.3.tar.gz

进入源码目录,打开README,按说明的步骤:先执行configure-ng.py脚本,然后make,make install。


$ python configure-ng.py 

Querying qmake about your Qt installation...

Determining the details of your Qt installation...

This is the GPL version of PyQt 4.10.3 (licensed under the GNU General Public

License) for Python 2.6.6 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

由于这是GPL,所以在执行configure-ng.py时让我们同意协议。输入yes继续。

用了1min顺利完成!接着make,这个过程有一点长,花了20分钟,很顺利。

最后是sudo make install,出了错误:


install -m 755 -p /home/hevake_lcj/Install/qt-downloads/PyQt-x11-gpl-4.10.3/pyuic4 /usr/bin/

strip /usr/bin/pyuic4

strip:/usr/bin/pyuic4: File format not recognized

make: [install_pyuic4] Error 1 (ignored)

最后,虽然这里安装有错误。我按官方例子写的几个程序都没有出现问题。

示例网址:http://zetcode.com/gui/pyqt4/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

后语:

其实CentOS的yum自带PyQt4的,可以用yum直接安装。


在macos上基于python2.7安装PyQt5 在macos上基于python2.7安装PyQt5 在python3上面安装PyQt5是十分简单的,可是,在python2.7上安装这个东西,着实让人折腾了一把。要总结一下,年纪大了,记性不好。 首先要安装最新版的Qt和python2,命令如下: brew install python qt5 接下来获取PyQt5的源码,命令如下: wget http://sourceforge.
Pyqt5学习系列 最近在学习Pyqt5做界面,找到了一个非常棒的博主的学习系列 在此记录下来: http://blog.csdn.net/zhulove86/article/category/6381941
李名赫 博主从事的是物联网行业,目前在某知名智能家居科技公司担任家庭智能中心研发主管。欢迎交流!