Ed Holloway-George
Ed Holloway-George

Reputation: 5149

Can't find GTK gi package OS X

I recently installed the pygtk using Homebrew in an attempt to run the following program:

#!/usr/bin/python3
from gi.repository import Gtk, GObject
import time

class TimerWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Timer")
        self.timer = Gtk.Label()
        self.add(self.timer)

    def update(self):
        self.timer.set_text(time.strftime('%H:%M:%S'))
        return True

if __name__ == "__main__":
  win = TimerWindow()
  win.connect("delete-event", Gtk.main_quit)
  win.show_all()
  GObject.timeout_add(200, win.update)
  Gtk.main()

This program works fine in multiple Linux distros but I am having some trouble getting it to work on my Mac.
It seems that python cannot find the gi package, which is strange as I have installed it (?). Admittedly I am very new to python so I may be mistaken.

The error given at runtime is as follows:

File "test.py", line 2, in <module>
    from gi.repository import Gtk, GObject
ImportError: No module named gi.repository

I have followed multiple guides online of how to install the libraries but none seem to have worked.
Has anyone got experience in this, or can make the program work correctly on OSX?

Many thanks

Upvotes: 2

Views: 2395

Answers (1)

LiuLang
LiuLang

Reputation: 773

Which directory is PyGObject(gi) installed? That package should have been moved to python path, and python will scan modules from these directories.

We can use this to get the current python path:

import sys
print(sys.path)

Yes, put gi package to one of these directories.

python and python3 have different path.

Upvotes: 3

Related Questions