gpt4 book ai didi

python - 找不到 GTK gi 包 OS X

转载 作者:太空宇宙 更新时间:2023-11-04 01:27:22 25 4
gpt4 key购买 nike

我最近使用 Homebrew 安装了 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.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

我在网上遵循了多个关于如何安装这些库的指南,但似乎都没有用。
有没有人有这方面的经验,或者可以使程序在 OSX 上正常运行?

非常感谢

最佳答案

PyGObject(gi) 安装在哪个目录?该包应该已经移动到 python 路径,python 将从这些目录中扫描模块。

我们可以使用它来获取当前的 python 路径:

import sys
print(sys.path)

是的,将 gi 包放到这些目录之一。

python 和 python3 有不同的路径。

关于python - 找不到 GTK gi 包 OS X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16864375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com