1. 程式人生 > >Linux下原始碼安裝PyQt4

Linux下原始碼安裝PyQt4

感謝朋友支援本部落格,歡迎共同探討交流,由於能力和時間有限,錯誤之處在所難免,歡迎指正!
如果轉載,請保留作者資訊。
部落格地址:http://blog.csdn.net/qq_21398167

原博文地址:http://blog.csdn.net/qq_21398167/article/details/46429655

官網上說:“Before you can build PyQt4 you must have already built and installed SIP” 意思是說必須先安裝SIP,於是也下載了SIP。

解壓SIP壓縮包,進入原始碼目錄,開啟README,說是當前目錄下有一個build.py,結果我沒有找到。但找到了一個configure.py的程式碼。於是我執行它

1 $ python configure.py

正常完成,並生成了Makefile。我下意識地執行make,結果:

1 2 3 4 5 6 7 8 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

1 sudo yum install python-devel

完成安裝。再make,順利通過編譯。再sudo make install,也很順利。測試是否完成安裝:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 $ 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 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

ImportError: No module named QtWebKit

進入原始碼目錄,開啟README,按說明的步驟:先執行configure-ng.py指令碼,然後make,make install。

因為我在使用 eric4 的時候   出現錯誤

ImportError: No module named QtWebKit

原因是在編譯 PyQt 的時候  沒有安裝 QtWebKit   導致沒有編譯那個模組
 
所以在編譯之前   yum install qtwebkit
1 2 3 4 5 6 7 8 9 10 11 12 $ 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分鐘,很順利。