6

I have Ubuntu 14.04 with python-2.7 and python-3 support. I am porting my python application from python-2.7 to python-3. I have example.py file which is importing below modules. and I #!/usr/bin/python3 as python evn variable.

import gtk, gobject, time, sys, os, subprocess, signal 

**ImportError: No module named 'gtk'**

I am getting above error, when trying to run with python3.

Any idea what is missing here?

2 Answers 2

7

try:

from gi.repository import Gtk

and replace gtk by Gtk in your code

or

from gi.repository import Gtk as gtk

see also : Python GTK+ 3 Tutorial : Getting Started

2
  • I get an error: AttributeError: 'gi.repository.Gtk' object has no attribute 'combo_box_new_text' May 25, 2020 at 14:56
  • ...and many many more errors. May 25, 2020 at 15:24
5

Use the GObject introspection based Python3 bindings for Gtk and friends:

from gi.repository import Gtk, GObject

That needs the package python3-gi which is installed by default.

Some names have changed since PyGTK. The Python GObject Introspection API Reference should help you to find the new names (and other changes).

1
  • 1
    Thank you for suggestion. I am not able to import many modules which been supported for 2.7 like gtk, gobject, time, sys, os, subprocess, signal. please share any document which has details and helpful for porting py-2 to py-3.
    – mrudula
    Nov 13, 2015 at 0:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .