Gtk3 | Python:命名空间Gtk不可用,命名空间'Gtk'(任何版本)的Typelib文件未找到(使用macos)

时间:2018-10-20 09:37:45

标签: python macos gtk gtk3 pygobject

我试图开始编写一些GTK程序,并测试GTK的安装和配置,我试图执行一个简单的helloworld脚本。

仅使用pygobject documentation给出的简单示例:

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

window = Gtk.Window(title="Hello World")
window.show()
window.connect("destroy", Gtk.main_quit)
Gtk.main()

第一个问题(已解决):

from gi.repository import Gtk 

Gtk not found, but a new autoimport give me this import:

from gi.overrides import Gtk

主要问题(未解决):

Traceback (most recent call last):
  File "/Users/alberto/PycharmProjects/p1-ipm-16-17-Otloal/main.py", line 2, in <module>
    gi.require_version("Gtk", "3.0")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gi/__init__.py", line 127, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available

已经安装了gtk + 3和pygobject3

brew reinstall gtk+3 pygobject3

**编辑: 如果我只是忽略gi.require_version(“ Gtk”,“ 3.0”)行,则python将从from gi.repository导入Gtk继续进行,其结尾为:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    from gi.overrides import Gtk
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gi/overrides/Gtk.py", line 39, in <module>
    Gtk = get_introspection_module('Gtk')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gi/module.py", line 265, in get_introspection_module
    module = IntrospectionModule(namespace, version)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gi/module.py", line 117, in __init__
    repository.require(namespace, version)
gi.RepositoryError: Typelib file for namespace 'Gtk' (any version) not found

*** edit2:     在linux中,解决该问题(我不知道它是否对我有用)的方法似乎是安装gir1.2-gtk-3.0,但这是一个debian软件包,我无法找到macOS。等价

0 个答案:

没有答案