在Ubuntu 12.10下搭建PyQt环境。
安装Python(由于此版本默认有Python2.7和Python3.2故可省去)
第一步:下载Qt4源代码:http://qt-project.org/downloads
第二步:下载SIP( SIP is a tool forautomatically generating Python bindings for C andC++ libraries):http://www.riverbankcomputing.co.uk/software/sip/download
第三步:下载PyQt:http://www.riverbankcomputing.co.uk/software/pyqt/download
第四步:配置SIP:
解压sip-XXXXX.tar.gz压缩包,进入sip-XXXXX目录
运行
python configure.py
注意:If you have multiple versions of Python installed then make sure
you use theinterpreter for which you wish SIP to generate bindings for.
也就是说我采用Python3.x进行开发,那么使用的命令是:python3 configure.py
shell下的结果是:
lieo@ubuntu:~/download/sip-4.14.2$ python3 configure.py
This is SIP 4.14.2 for Python 3.2.3 on linux2.
The SIP code generator will be installed in /usr/bin.
The sip module will be installed in /usr/lib/python3/dist-packages.
The sip.h header file will be installed in /usr/include/python3.2mu.
The default directory to install .sip files in is /usr/share/sip.
make
注意: 这步可能会报找不到Python.h文件的错误(没报错跳到make install)
这是因为缺失头文件和静态库包,
假如使用python2.7运行
sudo apt-get install python-dev
假如使用python3运行
sudo apt-get install python3-dev
make install
第五步:编译安装Qt4
Ubuntu默认没有编译环境,运行以下命令安装编译环境
sudo apt-get install build-essential
#进入qt源码目录运行
./configure
结果:Qt will be installed into /usr/local/Trolltech/Qt-4.8.4
make
make install
1.如果在./configure阶段,出现了以下错误
Basic XLib functionality test failed!
You might need to modify the include and library search paths by editing
QMAKE_INCDIR_X11 and QMAKE_LIBDIR_X11
那是因为没装有libxtst-dev,使用命令apt-get install libxtst-dev安装
2.如果在make阶段,出现一下错误
/usr/bin/ld: cannot find -lXrender
make[1]: *** [../../../../lib/libQtWebKit.so.4.7.3] 错误 1
make: *** [sub-webkit-make_default-ordered] 错误 2
那是因为没有装libxrender-dev
3.在qt create中,尝试编译测试,如果找不到qmake,则在工具-选项-QT4中手动设置qmake的位置。qmake的位置默认在/usr/local/Trolltech/Qt-4.8.4/bin/qmake。
当这几个步骤全部完成后,把“PATH=/usr/local/Trolltech/Qt-4.8.4/bin:$PATH
export PATH”加到.profile中,Qt就安装成功了。
或者 在.bashrc文件(如果你的shell是bash、ksh、zsh或者sh)中,添加下面这些行:
QTDIR=/usr/local/Trolltech/Qt-4.8.4
PATH=$QTDIR/bin:$PATH
LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
第六步:安装PyQt
#进入PyQt源码目录运行以下命令安装PyQt
#前提是Qt4和SIP以正确安装
python configure.py
make
make install
至此配置完成。