5

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?

6

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

4

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).

  • 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 '15 at 0:01

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.