gufw won't run: "ImportError: No module named gtk"

Asked by Rob Locher on 2011-01-24

Greetings all,

When I try to launch gufw, also known as the Firewall Configuration application, from the Applications menu in Maverick Meerkat (Netbook edition), nothing happens. So I tried to run it from the command line:

rob@teeny:~$ gufw
Traceback (most recent call last): File "/usr/share/gufw/", line 19, in <module>
    from instance import Check
  File "/usr/share/gufw/", line 18, in <module>
    import gtk
ImportError: No module named gtk

I Googled "ImportError: No module named gtk", and what I found seems to indicate that I might have some sort of python problem. I don't know what to do about it though, and I would be grateful for any help.

Question information

English Edit question
Ubuntu gui-ufw Edit question
No assignee Edit question
Solved by:
Eliah Kagan
Last query:
Last reply:

Please try to install/reinstall python-gtk2 from terminal type:

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get -f install
sudo apt-get --reinstall install python-gtk2

give your user password when requested, you don't see nothing when you type it, then press enter

Then retry...

Rob Locher (rclocher3) said : #2

Hi Marco, and thanks for your help. I'm sorry to say that it didn't work: I get the same error when I try to run gufw from the command line.

I remember now that several months ago I tried to install Python 2.5.5 from source to get a game working. (The game is FreeOrion, and the problem with it turned out to be a problem with OpenGL2.0 and my graphics adapter.) So I think I may have caused the problem. I don't remember if I was successful with the installation of Python 2.5.5 or not.

Are you able to run other python programs that use GTK, like the Update Manager?

Do you still have the Python 2.5.5 source from when you were trying (and possibly succeeding) to install it from source?

Also, please paste the output of this command:

ls -l /usr/local/src /usr/local/bin /usr/local/lib

[By the way, in case it becomes useful down the line: this situation is reminiscent of, and perhaps similar to, but not the same as, the situation in bug 22587, which was judged to be a configuration issue and not a bug.]

Rob Locher (rclocher3) said : #4

Eliah, thanks very much for considering my problem. I see now that the problem most likely has nothing to do with gufw. It's tremendously generous of you to volunteer your time. This community of Ubuntu users is wonderful and inspiring.

The Update Manager runs just fine. (If it didn't, I would have discovered this problem much sooner.)

I don't remember if I still have the source for my Python build attempt, but I think I probably do. I've looked around for the instructions that I followed, but I can't find them.

By the way, I have extensive Unix experience from the ancient days circa 1992, but not so much experience recently -- running Ubuntu is like meeting an old friend that I haven't seen in years.

Here's the output you requested:

rob@teeny:~$ ls -l /usr/local/src /usr/local/bin /usr/local/lib
total 6840
lrwxrwxrwx 1 root root 31 2010-11-27 23:12 freeorion-start -> /usr/games/freeorion//freeorion
-rwxr-xr-x 1 root root 96 2010-11-27 23:01 idle
-rwxr-xr-x 1 root root 81 2010-11-27 23:01 pydoc
-rwxr-xr-x 2 root root 3484254 2010-11-27 23:07 python
-rwxr-xr-x 2 root root 3484254 2010-11-27 23:07 python2.5
-rwxr-xr-x 1 root root 1424 2010-11-27 23:07 python2.5-config
lrwxrwxrwx 1 root root 16 2010-11-27 23:07 python-config -> python2.5-config
-rwxr-xr-x 1 root root 18051 2010-11-27 23:01

total 24
drwxr-xr-x 21 root root 20480 2010-11-27 23:07 python2.5
drwxrwsr-x 4 root staff 4096 2010-10-07 10:23 python2.6

total 0

Package management tools in Ubuntu install software in /usr/bin -- software installed in /usr/local/bin is installed manually by the user (or perhaps automatically by installers of software not provided by Ubuntu packages, though they should really be using someplace like /opt). By "the user," of course I really mean "the local system administrator."

Therefore, by examining some of the contents of /usr/local, we can see that you did manually install Python at some point, and that the installation (or at least some part of it) is still present. This is likely the cause of your problems.

Unfortunately, the python source is not in /usr/local/src, so you can't uninstall it by going into the relevant directories and running "sudo make uninstall".

However, it is probably safe to manually delete the files. In case that causes problems, though, I suggest backing them up first. For example:

cd /usr
sudo tar cf local.tar local

Your user account probably has read access to all those files, but maybe not. If you get any error messages saying you've been denied access, then you'll have to prefix that command with sudo.

Then remove both the directories inside /usr/local/lib, and all five entries in /usr/local/bin that start with py. There are potentially other ways, but especially if you feel comfortable reversing the change from a live CD, I'd just reboot--Ubuntu uses Python for lots of stuff, so it would be hard to make sure that nothing was running with the old "deleted" Python installation until you do reboot.

Note that your python installations (you appear to have manually installed python-2.5 and also python-2.6) installed more files than just the ones removed by following the above steps, but removing those will most likely be sufficient to let the system-provided Python work properly. You can weed the others out (for example, in /usr/local/man and /usr/local/share) at your leisure.

The other option is to download the python-2.5 and python-2.6 source tarballs (/usr/local/src is a good place to put them), unpack them, configure them, build them...and uninstall them. You might have to install them before you uninstall them--that's OK. If you decide to go that route and want help, I'd be pleased to provide it.

If you do that, it would be good to use the exact versions you used before...that was probably 2.5.5 for python-2.5, but I don't know if you have any idea about the specific minor version of python-2.6. But you should be able to find out, for certain, for both:

/usr/local/bin/python-2.5 --version
/usr/local/bin/python --version

(Or run "which python-2.5 python" to be sure, and then leave off the "/usr/local/bin" prefix.)

I've been assuming that /usr/local/bin/python is Python 2.6; it's possible, though, that it's the same as python-2.5, and that you have an incomplete Python 2.6 installation (containing some files in /usr/local/lib but none in /usr/local/bin). That's another reason to check the actual versions before doing anything drastic.

Welcome back to UNIX (or Unix-like, anyway)!

Rob Locher (rclocher3) said : #6

Eliah, thank you very much for the sage advice! I am just amazed that someone would voluntarily help me out of my silly jam.

I did a little more research on my system, and I found the source for Python 2.5.5, in ~/Downloads/tarballs/Python-2.5.5 . (Note to self: unlike some other non-free OSes, Linux has standard places where things go. Research that more before building anything else from source.)

Having found the source code, I triumphantly did "sudo make uninstall", only to discover that there is no uninstall target in the Makefile. I looked in the Makefile for other targets, and discovered one called "clobber". I found it very difficult to understand what "clobber" did from the Makefile, so I tried "sudo make clobber". Apparently that does the opposite of "./configure".

So after running "./configure" and "make" again, I had the bright idea to try "sudo make install > make-install.txt". So now I have a list of all the many hundreds or thousands of things that "make install" does. (It seems as though mostly it copies a bunch of .py files around.)

That takes me back to your original instructions to clear out /usr/local/lib, /usr/local/bin, and so on. I'll do that next (immediately after I discharge a social obligation). I will of course report the results.

By the way, I don't remember installing Python 2.6 at all, and I don't see 2.6's tarball or source tree anywhere.

- Rob

Rob Locher (rclocher3) said : #7

It worked! Hooray! By the way, I think Python 2.6 may have been installed by the installer for a program "Sigil" that I downloaded to edit EPUB files (electronic books).

Thank you so very much for your help Eliah. I am tremendously grateful.

Rob Locher (rclocher3) said : #8

Thanks Eliah Kagan, that solved my question.

I'm glad your problem is solved.

Often "make uninstall" won't work until "make install" has been run.

You're right that "make clobber" is a strange target. Typically "make clean" undoes all the build steps, "make distclean" undoes all the build steps and the configuration as well (perhaps "make clobber" was an alias of "make distclean"?), and (this is a bit less standardized) "make realclean" undoes the pre-distribution steps of automatically generating the configure script and related files.

There are various EPub readers that are packaged for Ubuntu and available for automatic installation, if you need an EPub reader in the future and don't want to bother manually building and installing something. Two of them are FBReader and Calibre. See