Linux 安裝 wxPython4.0.4

Ubuntu 18.04 安裝 wxPython4.0.4python

 

由於 wxPython4.x 不提供 Linux 下的 bin 文件安裝,如下記錄 Ubuntu 18.04 的安裝過程 (Ubuntu 18.04 已默認安裝 Python 3.6.8)。linux

1)安裝 gtk-2.0 (你也可使用 libgtk-3-dev,若是你打算用 gtk3)ubuntu

$ sudo apt-get install libgtk2.0-dev 

2)安裝必要的庫centos

$ sudo apt-get install libcanberra-gtk-module

3)安裝 gtk 頭文件自動查找工具工具

$ sudo apt-get install pkg-config

4)查看一下oop

$ pkg-config --list-all | grep gtk
gtk+-unix-print-2.0            GTK+ - GTK+ Unix print support
gtk+-x11-2.0                   GTK+ - GTK+ Graphical UI Library (x11 target)
gtk+-2.0                       GTK+ - GTK+ Graphical UI Library (x11 target)

Ubuntu 18.04 默認已安裝 libgtk2.0-0,libgtk2.0-dev,libgtk2.0-bin,libgtk2.0-common,手動安裝一下 libgtk-3-0,libgtk-3-common,libgtk-3-bin,libgtk-3-dev,再查看一下,測試

$ pkg-config --list-all | grep gtk
gtk+-3.0                       GTK+ - GTK+ Graphical UI Library
gtk+-unix-print-2.0            GTK+ - GTK+ Unix print support
gtk+-x11-2.0                   GTK+ - GTK+ Graphical UI Library (x11 target)
gtk+-broadway-3.0              GTK+ - GTK+ Graphical UI Library
gtk+-unix-print-3.0            GTK+ - GTK+ Unix print support
gtk+-wayland-3.0               GTK+ - GTK+ Graphical UI Library
gtk+-x11-3.0                   GTK+ - GTK+ Graphical UI Library
gtk+-2.0                       GTK+ - GTK+ Graphical UI Library (x11 target)

5)下載對應 linux,python 和 gtk 版本(這裏選擇 gtk3) 的 wxPython 安裝 whl 文件 (例如我這裏下載 wxPython-4.0.4-cp36-cp36m-linux_x86_64.whl )網站

https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04/spa

6)安裝unix

$ sudo pip3 install wxPython-4.0.4-cp36-cp36m-linux_x86_64.whl

7)測試

$ python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import wx
>>> a = wx.App()
>>> wx.Frame(None, title='hello world').Show(); a.MainLoop();

 

CentOS7 安裝 wxPython4.0.4

 

由於 wxPython4.x 不提供 Linux 下的 bin 文件安裝,如下記錄 CentOS 7 的安裝過程 (CentOS 7 默認沒有安裝 Python 3)。

1)先安裝 python3 (默認爲 3.6.6)

$ sudo yum install python36.x86_64
$ sudo yum install python36-devel.x86_64
$ sudo yum install python36-pip.noarch
$ sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade pip
$ sudo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade pip

2)查看 gtk 版本 

$ pkg-config --list-all | grep gtk
gtk+-unix-print-2.0       GTK+ - GTK+ Unix print support
gtk+-x11-2.0              GTK+ - GTK+ Graphical UI Library (x11 target)
gtk+-2.0                  GTK+ - GTK+ Graphical UI Library (x11 target)

CentOS 7 默認已安裝 gtk2-2.24.31-1.el7.x86_64, gtk2-devel-2.24.31-1.el7.x86_64, gtk3-3.22.30-3.el7.x86_64, 手動安裝一下 gtk3-devel-3.22.30-3.el7.x86_64,再檢查一下,

$ pkg-config --list-all | grep gtk
gtk+-unix-print-2.0       GTK+ - GTK+ Unix print support
gtk+-3.0                  GTK+ - GTK+ Graphical UI Library
gtk+                      GTK+ - GIMP Tool Kit
gtk+-x11-2.0              GTK+ - GTK+ Graphical UI Library (x11 target)
gtk+-wayland-3.0          GTK+ - GTK+ Graphical UI Library
gtk+-unix-print-3.0       GTK+ - GTK+ Unix print support
gtk+-x11-3.0              GTK+ - GTK+ Graphical UI Library
gtk+-2.0                  GTK+ - GTK+ Graphical UI Library (x11 target)

3)下載對應 linux,python 和 gtk 版本(這裏選擇 gtk3) 的 wxPython 安裝 whl 文件 (例如我這裏下載 wxPython-4.0.4-cp36-cp36m-linux_x86_64.whl )

https://extras.wxpython.org/wxPython4/extras/linux/gtk3/centos-7/

4)安裝

$ sudo pip3 install wxPython-4.0.4-cp36-cp36m-linux_x86_64.whl

5)測試

$ python3
Python 3.6.6 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import wx
>>> a = wx.App()
>>> wx.Frame(None, title='hello world').Show(); a.MainLoop();

 

詳情參考 wxPython 官方網站

相關文章
相關標籤/搜索