4

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, which 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

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Otloal
  • 85
  • 2
  • 9
  • On an M1 mac, I got past this error by running `brew install spice-gtk pygobject3 gtk+3 py3cairo pango gobject-introspection libsoup` and setting `DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib`. But then I got a segfault. – LyteFM May 06 '21 at 17:15

0 Answers0