Ubuntu 18.04 安装 wxPython4.0.4
因为 wxPython4.x 不提供 Linux 下的 bin 文件安装,以下记录 Ubuntu 18.04 的安装过程 (Ubuntu 18.04 已默认安装 Python 3.6.8)。
1)安装 gtk-2.0 (你也可以使用 libgtk-3-dev,如果你打算用 gtk3)
$ sudo apt-get install libgtk2.0-dev
2)安装必要的库
$ sudo apt-get install libcanberra-gtk-module
3)安装 gtk 头文件自动查找工具
$ sudo apt-get install pkg-config
4)查看一下
$ 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/
6)安装
$ 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 官方网站。