Ubuntu 18.04 安装 wxPython4.0.4

因为 wxPython4.x 不提供 Linux 下的 bin 文件安装,以下记录 Ubuntu 18.04 的安装过程。

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)

5)下载对应 linux,python 和 gtk 版本的 wxPython 安装 whl 文件 (例如我这里下载 wxPython-4.0.4-cp36-cp36m-linux_x86_64.whl )

https://extras.wxpython.org/wxPython4/extras/linux/gtk2/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();

详情参考 wxPython 官方网站

猜你喜欢

转载自www.cnblogs.com/gaowengang/p/10847075.html