问题
I'm trying to start making a little GTK program, and to test GTK installation and config I'm trying to execute a simple helloworld script.
Just using a simple example given by 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()
First issue (resolved):
from gi.repository import Gtk
Gtk not found, but a new autoimport give me this import:
from gi.overrides import Gtk
Main issue (UNRESOLVED):
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
Already installed gtk+3 and pygobject3
brew reinstall gtk+3 pygobject3
**edit: If I just ignore the gi.require_version("Gtk", "3.0") line, python proceeds with the from gi.repository import Gtk, wich ends in:
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: In linux seems that the way to fix that kind of issue (I don't know if it would work for me) is installing gir1.2-gtk-3.0, but this is a debian package and I'm unable to find a macos equivalent
来源:https://stackoverflow.com/questions/52904290/gtk3-python-namespace-gtk-not-available-typelib-file-for-namespace-gtk-an