本文主要講述在linux環境下進行編譯wxpython,在windows下面安裝wxpython很簡單,只要下載,而後直接執行exe文件,下一步下一步便可安裝,在linux下面,則具備不少步驟。php
wxpython下載地址爲:python
http://wxpython.org/download.php
具體的源碼下載路徑在最下面的位置,名稱爲wxPython-src,點擊便可下載。下載的文件名稱爲wxPython-src-3.0.2.0.tar.bz2.linux
進行解壓:windows
[root@FTP ~]# tar -jxvf wxPython-src-3.0.2.0.tar.bz2
gtk2,gtk2-devel,python-devel,tk,tk-devel,gstreamer,gstreamer-devel,mesa-libGL-devel,
mesa-libGLU-devel,mesa-libGLU,mesa-libGL,libSM,libSM-devel,gstreamer-plugins-base-devel
最好是利用yum進行安裝。。不然會崩潰的bash
新建一個臨時路徑來保存編譯的結果,以下所示:服務器
[root@FTP wxPython-src-3.0.2.0]# mkdir bld [root@FTP wxPython-src-3.0.2.0]# cd bld [root@FTP bld]# ../configure --prefix=/usr/local/pythonwxpython --with-gtk --with-gnomeprint
--with-opengl --enable-debug --enable-geometry --enable-graphics_ctx --enable-sound --with-sdl
--enable-mediactrl --enable-display --disable-debugreport --enable-unicode --with-libjpeg=builtin
--with-libpng=builtin --with-libtiff=builtin --with-zlib=builtin
新建bld來保存編譯的結果,主要是因爲編譯的時候,佔用的空間有1G多,因此須要用一個新的目錄進行編譯,注意上面configure前面有兩個點。app
編譯結果以下:測試
進行安裝:ui
make && make install
[root@FTP local]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_ftp-lv_root 9.9G 6.1G 3.3G 66% / tmpfs 387M 0 387M 0% /dev/shm /dev/sda1 485M 32M 428M 7% /boot [root@FTP local]# date Tue Apr 5 13:07:07 EDT 2016 [root@FTP local]# date Tue Apr 5 13:14:56 EDT 2016 [root@FTP local]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_ftp-lv_root 9.9G 8.1G 1.3G 87% / tmpfs 387M 0 387M 0% /dev/shm /dev/sda1 485M 32M 428M 7% /boot
進行安裝wxpython:--WX_CONFIG就是前面編譯configure的路徑debug
[root@FTP wxPython]# python setup.py build_ext --inplace --debug WX_CONFIG=/usr/local/pythonwxpython/bin/wx-config
安裝以後,設置wxpython的環境變量:
export PYTHONPATH="/usr/local/wxPython" export LD_LIBRARY_PATH="/usr/local/pythonwxpython/lib
能夠添加在用戶加目錄中,另外必須將wxpython添加到pythonpath中,以下:
[root@FTP wxPython-src-3.0.2.0]# cp -r wxPython /usr/local/wxPython/
拷貝主要是爲了對應上面的PYTHONPATH
在進行從新編譯的時候,必須先進行清除前面編譯的文件,使用的命令以下:
make distclean
若是使用makeclean,是不能夠的,報錯信息以下:
configure: error: source directory already configured; run "make distclean" there first configure: error: ../../../src/tiff/configure failed for src/tiff
若是使用上面的命令不能清除,那麼仍是從新解壓進行編譯吧
導入wx模塊的時候,出錯,出錯內容以下:
>>> import wx Traceback (most recent call last): File "<stdin>", line 1, in <module> File "wx/__init__.py", line 45, in <module> from wx._core import * File "wx/_core.py", line 4, in <module> import _core_ ImportError: libwx_gtk2u_xrc-3.0.so.0: cannot open shared object file: No such file or directory
設置環境變量LD_LIBRARY_PATH:
[root@FTP wxPython]# cat ~/.bash_profile |grep LD export LD_LIBRARY_PATH="/usr/local/pythonwxpython/lib
將環境變量寫在用戶文件中,從而每次均可以直接使用。
在別的路徑導入wx模塊的時候,報錯以下:
[root@FTP ~]# python Python 2.7.11 (default, Apr 5 2016, 12:30:11) [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import wx Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named wx
[root@FTP wxPython-src-3.0.2.0]# cp -r wxPython /usr/local/wxPython [root@FTP wxPython-src-3.0.2.0]# cat ~/.bash_profile |grep PYTHON export PYTHONPATH="/usr/local/wxPython"
具體的報錯內容以下:
*** Could not run GTK+ test program, checking why... *** The test program failed to compile or link. See the file config.log for the *** exact error that occured. This usually means GTK+ is incorrectly installed. configure: error: The development files for GTK+ were not found. For GTK+ 2, please ensure that pkg-config is in the path and that gtk+-2.0.pc is installed. For GTK+ 1.2 please check that gtk-config is in the path, and that the version is 1.2.3 or above. Also check that the libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config --libs' are in the LD_LIBRARY_PATH or equivalent.
主要查看是否安裝了gtk2和gtk2-devel包,安裝上這兩個包便可
有人說須要安裝pkgconfig包,本系統中已經安裝了這個包,因此未進行測試。
具體的報錯內容以下:
configure: No package 'gstreamer-1.0' found configure: error: no gstreamer-1.0 >= 1.0.0 (GStreamer) found
[root@FTP demo]# rpm -qa |grep ^gstreamer* gstreamer-plugins-base-0.10.29-1.el6.x86_64 gstreamer-0.10.29-1.el6.x86_64 gstreamer-devel-0.10.29-1.el6.x86_64 gstreamer-plugins-base-devel-0.10.29-1.el6.x86_64 gstreamer-tools-0.10.29-1.el6.x86_64
具體的報錯內容以下:
configure: error: OpenGL libraries not available
[root@FTP demo]# rpm -qa|egrep "mesa-libGL-devel|mesa-libGLU-devel" mesa-libGL-devel-7.11-3.el6.x86_64 mesa-libGLU-devel-7.11-3.el6.x86_64
注意沒有帶devel的包也要相應的裝上。
在進行安裝wxpython的時候,若是出現不少編譯錯誤,直接加上參數BUILD_GLCANVAS=0,也能夠直接忽略。
[root@FTP wxPython]# python setup.py build_ext --inplace --debug WX_CONFIG=/usr/local/pythonwxpython/bin/wx-config BUILD_GLCANVAS=0
若是出現其餘的問題的話,基本都是依賴包的問題,依次進行安裝上述的依賴包便可。