Python Can';找不到GTK gi包OSX
我最近使用自制软件安装了pygtk,试图运行以下程序:Python Can';找不到GTK gi包OSX,python,python-3.x,gtk,Python,Python 3.x,Gtk,我最近使用自制软件安装了pygtk,试图运行以下程序: #!/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.
#!/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()
这个程序在多个Linux发行版中运行良好,但我在Mac上运行时遇到了一些问题。python似乎找不到
gi
包,这很奇怪,因为我安装了它(?)。诚然,我对python非常陌生,所以我可能弄错了。运行时给出的错误如下:
File "test.py", line 2, in <module>
from gi.repository import Gtk, GObject
ImportError: No module named gi.repository
文件“test.py”,第2行,在
从gi.repository导入Gtk,GObject
ImportError:没有名为gi.repository的模块
我在网上查阅了多个关于如何安装库的指南,但似乎没有一个有效。有没有人在这方面有经验,或者可以使程序在OSX上正常工作?
非常感谢PyGObject(gi)安装在哪个目录?该包应该已经移动到python路径,python将扫描这些目录中的模块 我们可以使用它来获取当前python路径:
import sys
print(sys.path)
是的,将gi包放在这些目录之一
python和python3有不同的路径