1
votes

I installed gtk+ on my Ubuntu 13.10 successfully(apparently!) using jhbuild following this link: http://python-gtk-3-tutorial.readthedocs.org/en/latest/install.html

but when i run the following simple program:

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

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

i get this error:

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

On searching around a bit , i found these similar questions:

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

but i still get the error.

and these:

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

don't really give a solution.

How can i fix this?

UPDATE 1: So, apparently the error was due to GtkWindow instead of Gtk.Window in the code, but even after correcting it , the same warnings are displayed (although, now i don't get the error and get the correct output)

3

3 Answers

1
votes

According to your traceback:

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

In your code sample on line 4 you have:

win = Gtk.Window()

But the error is indicating you actually have:

win=GtkWindow()

You accidentally omitted the . between Gtk and Window in your actual code but fixed it in the example you posted. I'd suggest double checking that line in intro.py to see if this fixes your problem.

  • NOTE: This is entirely unrelated to the warnings about failing to load those 3 modules.
0
votes

To me the right answer was to specify the GTK module position: simply write in the terminal

export GTK_PATH=/usr/lib/x86_64-linux-gnu/gtk-2.0

and a similar reasoning for the other modules.

-1
votes

Try reinstalling the package, it may have been an error when installation happened.