歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu 12.10下搭建PyQt環境

Ubuntu 12.10下搭建PyQt環境

日期:2017/2/28 14:55:09   编辑:Linux教程

在Ubuntu 12.10下搭建PyQt環境。

make

安裝Python(由於此版本默認有Python2.7和Python3.2故可省去)

第一步:下載Qt4源代碼

第二步:下載SIP( SIP is a tool forautomatically generating Python bindings for C andC++ libraries)

第三步:下載PyQt

第四步:配置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

至此配置完成

Copyright © Linux教程網 All Rights Reserved