如何在Mac OS X上安装pygtk 3? [英] How to install pygtk 3 on Mac OS X?
问题描述
我尝试过的事情:
brew install pygobject3 --with-python@2 gtk+3
brew install pygtk3
brew install pygobject3
pip install pygobject
python -c 'import gi; gi.require_version("Gtk", "3.0")'
结果:
ValueError: Namespace Gtk not available for version 3.0
请注意,我正在使用python 3.6运行conda;和Mac OS X High-Sierra
Note that I'm running conda, with python 3.6; and Mac OS X High-Sierra
发布前,我会仔细阅读以下问题/答案:
I read through the following questions/answers before posting:
- 在Mac OS X上安装pygtk的最简单方法
- Python Gtk3可执行文件
- https://github.com/neovim/python-gui/issues/33
- https://github.com/neovim/python-gui#dependencies-debian
- https://github.com/pybee/toga/issues/38
- 错误无法找到Gtk的任何类型库"使用Python3和GTK3
- https://github.com/neovim/python-gui/issues/33
- pyGtk:获取版本时Gtk丢失错误
- Easiest way to install pygtk on Mac OS X
- Python Gtk3 executable
- https://github.com/neovim/python-gui/issues/33
- https://github.com/neovim/python-gui#dependencies-debian
- https://github.com/pybee/toga/issues/38
- Error "Could not find any typelib for Gtk" with Python3 and GTK3
- https://github.com/neovim/python-gui/issues/33
- pyGtk: Gtk missing error when get version
(请注意,如果我将requires
更改为2.0
,则加载正常,但会收到警告:
(Note that if I change the requires
to 2.0
, then it loads ok, but I get a warning:
"RuntimeWarning:您已经导入了Gtk 2.0模块.由于Gtk 2.0并非设计用于自省,因此某些接口和API将会失败.因此pygobject开发团队不支持此操作,我们建议您移植您的应用在Gtk 3或更高版本上使用.PyGTK是与Gtk 2.0一起使用的推荐python模块" )
"RuntimeWarning: You have imported the Gtk 2.0 module. Because Gtk 2.0 was not designed for use with introspection some of the interfaces and API will fail. As such this is not supported by the pygobject development team and we encourage you to port your app to Gtk 3 or greater. PyGTK is the recomended python module to use with Gtk 2.0" )
推荐答案
问题是pygobject3的开发人员已编写了不考虑pip/conda的安装说明.如果您遵循官方文档:
The problem is that the developers of pygobject3 have written their install instructions that does NOT consider pip/conda. If you follow the official documentation:
- 必须使用自制python安装程序(您在
brew install python
上安装的程序) -
brew install gtk+3
与非自制Pip/Conda python安装不兼容.您必须手动构建GTK3软件包才能使用pygobject3的pip版本.
- Have to use the homebrew python installation (the one installed when you go
brew install python
) brew install gtk+3
is NOT compatible with non homebrew Pip/Conda python installs. You have to build the GTK3 package manually to use the pip version of pygobject3.
但是,如果您想使用conda,请感谢此conda贡献者,您可以使用一个预先构建的conda gtk3软件包,您只需要从他的频道获取它即可:
However if you want to use conda, thanks to this conda contributor, there is a pre-built conda gtk3 package you can use, you just have to get it from his channel:
使用conda创建新环境:
Make a new environment using conda:
conda create --name my_env
从conda安装pygobject3
install pygobject3 from conda
conda install pygobject
从pkgw-forge频道安装gtk3
install gtk3 from the pkgw-forge channel
conda install -c pkgw-forge gtk3
要进行验证,请在conda env中打开python并运行
To verify, open python from within the conda env and run
import gi
gi.require_version("Gtk", "3.0")
应该没有错误
这篇关于如何在Mac OS X上安装pygtk 3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!