python - Gtk 消息 : Failed to load module

标签 python linux gtk

我使用 jhbuild 在我的 Ubuntu 13.10 上成功地(显然!)安装了 gtk+,点击这个链接: http://python-gtk-3-tutorial.readthedocs.org/en/latest/install.html

但是当我运行以下简单程序时:

 #!/usr/bin/python
from gi.repository import Gtk

win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

我收到这个错误:

Gtk-Message: Failed to load module "overlay-scrollbar"
Gtk-Message: Failed to load module "unity-gtk-module"
Gtk-Message: Failed to load module "canberra-gtk-module"
Traceback (most recent call last):
  File "intro.py", line 4, in <module>
    win=GtkWindow()
NameError: name 'GtkWindow' is not defined

在四处搜索了一下,我发现了这些类似的问题:

https://askubuntu.com/questions/342202/failed-to-load-module-canberra-gtk-module-but-already-installed https://askubuntu.com/questions/208431/failed-to-load-module-canberra-gtk-module?rq=1

但我仍然得到错误。

还有这些:

Python Gtk+ development in Linux using Eclipse + PyDev, Unresolved import: Gtk PyCharm can not resolve PyGObject 3.0, but code runs fine

不要真的给出解决方案。

我该如何解决这个问题?

更新 1:所以,显然错误是由于代码中的 GtkWindow 而不是 Gtk.Window,但即使在更正它之后,也会显示相同的警告(尽管,现在我没有得到错误并得到正确的输出)

最佳答案

根据你的回溯:

Traceback (most recent call last):
  File "intro.py", line 4, in <module>
    win=GtkWindow()
NameError: name 'GtkWindow' is not defined

在第 4 行的代码示例中,您有:

win = Gtk.Window()

但错误表明你实际上有:

win=GtkWindow()

您在实际代码中不小心省略了 .Window 之间的 . 但在您发布的示例中修复了它。我建议仔细检查 intro.py 中的那一行,看看是否能解决您的问题。

  • 注意:这与未能加载这 3 个模块的警告完全无关。

关于python - Gtk 消息 : Failed to load module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22270826/

相关文章:

python - 使用较低级别的数据过滤分层 Pandas Dataframe 中的顶级类别

python - Pandas 使用来自 df 的值从 df 返回值

linux - 在 Arch Linux 上安装 libi2c-dev

linux - 了解事件是否发生(运行 gtk_dialog_run() 时)

python - 检测 wnck python 中窗口何时打开

linux - gtkdialog 中文本字段中的文本值未刷新

python - `Concatenate` 层需要具有匹配形状的输入(连接轴除外)

python - 如何在一行上一次打印一个字符?

xml - 如何提取XML文件的特定元素?

python - 您如何使用在后台运行的 python 脚本轮询 JSON 文件中的更改并提取更改?