[PYTHON] 安装PyQt [一]

### Install ######
1. Install Python
$ python --version
$ 3.2.3
Has been installed already, so pass this step.

2. Install QT
qmake -v : OS crashed, and reboot;
## sudo apt-get install --yes qtdeclarative5-dev qtdeclarative5-qtquick2-plugin qt5-default qtbase5-private-dev

Install from offical page: (reg_1025@163.com    @ Sammy_1009)
http://mirrors.ustc.edu.cn/qtproject/archive/online_installers/2.0/qt-unified-linux-x32-2.0.3-1-online.run
http://mirrors.ustc.edu.cn/qtproject/archive/online_installers/2.0/qt-unified-linux-x86-2.0.3-1-online.run
http://mirrors.ustc.edu.cn/qtproject/archive/online_installers/2.0/

./qt-unified-linux-x86-online.run

@ default qt version:
安装完Qt后,在某些Qt的命令行程序中是以文件 /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf 的配置为基准的,文件中默认使用qt4,如果需要配置为qt5,那么需要修改该文件,更改为qt5:
/usr/lib/x86_64-linux-gnu/qt5/bin
/usr/lib/x86_64-linux-gnu

@./Tools/QtCreator/bin/qtcreator
运行 qt creator


3. Install pyQT
a) download from: https://sourceforge.net/projects/pythonqt/
    pyQt does not include a copy of Qt. You must obtain a correctly licensed copy of Qt yourself.
b) install SIP
    SIP是一个自动为C和C++库生成Python扩展模块的工具。为了方便开发PyQt,SIP于1998被“Riverbank Computing”公司创造出来。
    不过,SIP不专用于PyQt,而是适用于所有的C和C++库。使用SIP时,程序员首先要编写一个特殊的".sip"文件,使用类似于C++的语法在其中描述扩展模块所提供的类型与函数。
    然后用SIP将这个文件转化为C++代码。最终编译,与C、C++库链接后就成为Python扩展模块。".sip"文件类似于C、C++的头文件。
    根据需要,需要程序员用SIP定义的语法添加一些C++代码中没有的信息。
    因为SIP不支持完整的C++语法,所以不能直接使用C++的头文件作为".sip"文件。
    
    http://blog.csdn.net/a359680405/article/details/45074761    for windows
    http://blog.csdn.net/sunny2038/article/details/7237630
    
    $ python configure.py --platform=linux-g++; make; make install    
    [error] python.h no such file or directory
    [fix] apt-get install python3-dev
    
    $ Hello SIP
    Refer to: http://blog.csdn.net/sunny2038/article/details/7237630

    在官网(https://riverbankcomputing.com/software/pyqt/intro)上下载SIP的Linux下的tar.gz格式的代码包,解压到某个目录中。然后在终端中进入该目录,依次输入python configure.py --platform linux-g++;make;make install即可。

   测试SIP

   a) 编写个C文件,功能是将两个数字相加并输出,命名为add.c,这个将成为在Python中的模块名 

/* File : add.c */  
int add(int x, int y)   
{    
    int g;    
    g = x + y;  
    return g;  
} 

  b) 手工编写SIP文件,在使用SIP的过程中,一个C/C++的源码文件,必须对应一个同名的sip文件,命名为add.sip

/* Define the SIP wrapper to the add library. */  
%Module(name=add, language="C")  
int add(int x, int y);   

   这里的C源码文件没有头文件,所以对应的sip文件很简单。如果C/C++的源码是实现部分,在实现部分还包括接口部分,即头文件。那么在相应的sip文件中需要用

  

%TypeHeaderCode  
#include <word.h>  
%End  

   c) 编译C文件。按照官网的说法,是编写configure.py,但别急,先做一些必不可少的工作。在命令行将add.c编译成add.o文件:输入

gcc -c add.c  
ar -r libadd.a add.o  

   d) 手工编写configure.py文件

    import os  
    import sipconfig  
      
    # The name of the SIP build file generated by SIP and used by the build  
    # system.  
    build_file = "add.sbf"  
      
    # Get the SIP configuration information.  
    config = sipconfig.Configuration()  
      
    # Run SIP to generate the code.  
    os.system(" ".join([config.sip_bin, "-c", ".", "-b", build_file, "add.sip"]))  
      
    # Create the Makefile.  
    makefile = sipconfig.SIPModuleMakefile(config, build_file)  
      
    # Add the library we are wrapping.  The name doesn't include any platform  
    # specific prefixes or extensions (e.g. the "lib" prefix on UNIX, or the  
    # ".dll" extension on Windows).  
    makefile.extra_libs = ["add"]  
      
    # Generate the Makefile itself.  
    makefile.generate()  

   e) build

python configure.py
make
make install

   f) 测试

>>>import add  
>>>add.add(4, 7)  
11  
>>>  

   g) others

   [error] python.h no such file or directory
   [fix] apt-get install python3-dev

 

   [error] cannot find -ladd

   [fix] add [-L ./ -ladd] in Makefile

   
    $sip -v
        4.18.1
c) install PyQt
    $python configure.py --qmake=/home/chenxm/Qt/5.5/gcc/bin/qmake

posted @ 2016-08-17 11:55  Bouygues  阅读(1532)  评论(0编辑  收藏  举报