简体   繁体   English

如何在 Mac OS X 上安装 pygtk 3?

[英]How to install pygtk 3 on Mac OS X?

What I tried:我试过的:

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")'

Result:结果:

ValueError: Namespace Gtk not available for version 3.0

Note that I'm running conda, with python 3.6;请注意,我正在使用 python 3.6 运行 conda; and Mac OS X High-Sierra和 Mac OS X High-Sierra

I read through the following questions/answers before posting:在发布之前,我通读了以下问题/答案:

(Note that if I change the requires to 2.0 , then it loads ok, but I get a warning: (请注意,如果我将requires更改为2.0 ,则它可以正常加载,但是我收到警告:

"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" ) "RuntimeWarning: 您已经导入了 Gtk 2.0 模块。因为 Gtk 2.0 不是为使用自省而设计的,某些接口和 API 将失败。因此,pygobject 开发团队不支持这一点,我们鼓励您将您的应用程序移植到Gtk 3 或更高版本。PyGTK 是推荐用于 Gtk 2.0" 的 Python 模块

The problem is that the developers of pygobject3 have written their install instructions that does NOT consider pip/conda.问题是 pygobject3 的开发人员编写了不考虑 pip/conda 的安装说明。 If you follow the official documentation:如果您遵循官方文档:

  • Have to use the homebrew python installation (the one installed when you go brew install python )必须使用 homebrew python 安装(你去brew install python时安装的那个)
  • brew install gtk+3 is NOT compatible with non homebrew Pip/Conda python installs. brew install gtk+3与非自制 Pip/Conda python 安装不兼容。 You have to build the GTK3 package manually to use the pip version of pygobject3.您必须手动构建 GTK3 包才能使用 pygobject3 的 pip 版本。

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,感谢这个 conda 贡献者,你可以使用一个预构建的 conda gtk3 包,你只需要从他的频道获取它:

Make a new environment using conda:使用 conda 创建一个新环境:

conda create --name my_env

install pygobject3 from conda从 conda 安装 pygobject3

conda install pygobject

install gtk3 from the pkgw-forge channel从 pkgw-forge 频道安装 gtk3

conda install -c pkgw-forge gtk3

To verify, open python from within the conda env and run要验证,请从 conda env 中打开 python 并运行

import gi
gi.require_version("Gtk", "3.0")

Should get no errors应该没有错误

I had the same problem.我有同样的问题。 I tried我试过了

$ brew install pygobject3 gtk+3 $ brew install pygobject3 gtk+3

and it was smoothly installing.并且安装很顺利。 Then checked as Jeff's answer:然后检查杰夫的回答:

$ python3 -c 'import gi; $ python3 -c 'import gi; gi.require_version("Gtk", "3.0"); gi.require_version("Gtk", "3.0"); print("ok")'打印(“确定”)'

got ok.没事。

Hope this helps,希望这有帮助,

Cheers干杯

I had the same problem.我有同样的问题。 I followed the instructions onpygobject web .我按照pygobject web上的说明进行操作

  • install homebrew安装自制软件
  • Execute brew install pygobject3 --with-python@2 gtk+3执行 brew install pygobject3 --with-python@2 gtk+3
  • Run python3 hello.py运行 python3 hello.py

Everything is fine now (note I use python3 not python for the test) :现在一切都很好(注意我使用 python3 而不是 python 进行测试):

$ python3 -c 'import gi; gi.require_version("Gtk", "3.0"); print("ok")'
ok

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM