You are not logged in.

#1 2015-07-27 06:29:18

mahesmohan
Member
From: India
Registered: 2013-06-08
Posts: 12

[SOLVED] Python. No module named gtk

This is one of the most stupidest thing I've ever done.

Recently for installing kivy I had to remove my site packages for both python 2.7 and python 3.4 in my Arch since installing kivy was aborted due to conflicts. During that time I also deleted a lot of other python files and directories. I removed both versions of python too.

I knew that reinstalling the whole thing would bring back things to normal, and to my luck most of it did. But recently I found that I cannot import gtk module. I tried installing pygtk via pip and using pacman and I still cant seem to import gtk. How can I bring back gtk ?

Last edited by mahesmohan (2015-07-29 09:10:52)

Offline

#2 2015-07-27 08:38:12

mauritiusdadd
Member
From: Benevento, Italy
Registered: 2013-10-27
Posts: 776

Re: [SOLVED] Python. No module named gtk

What command are you using to import the gtk module and in which python version? As far as I know pygtk is only for python2 and for python3 you should use the GObject Inspector module: https://python-gtk-3-tutorial.readthedo … le-example. However, what is the output of the following commands?

pacman -Qkk pygtk
python2 -c 'import sys; print("\n".join(sys.path))'

About me - github

-- When you have eliminated the impossible, whatever remains, however improbable, must be the truth -- Spock | Sherlock Holmes

Offline

#3 2015-07-27 20:04:38

mahesmohan
Member
From: India
Registered: 2013-06-08
Posts: 12

Re: [SOLVED] Python. No module named gtk

I noticed the issue when I tried running guake which used to work perfectly before the deletion, I tried running it from the CLI and got a Traceback with message

ImportError: No module named gtk

Here is the complete Traceback

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/site-packages/guake/main.py", line 28, in <module>
    import gtk
ImportError: No module named gtk

I believe the traceback answers your question regarding the version of python and command used to import gtk module.
Here is the output of the commands you asked me to run:

pacman -Qkk pygtk
pygtk: 678 total files, 0 altered files

python2 -c 'import sys; print("\n".join(sys.path))'

/usr/lib/python27.zip
/usr/lib/python2.7
/usr/lib/python2.7/plat-linux2
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/lib/python2.7/site-packages
/usr/lib/python2.7/site-packages/gst-0.10

Offline

#4 2015-07-28 05:30:51

mauritiusdadd
Member
From: Benevento, Italy
Registered: 2013-10-27
Posts: 776

Re: [SOLVED] Python. No module named gtk

This is the output on my machine:

$ python2 -c 'import sys; print("\n".join(sys.path))'

/usr/lib/python27.zip
/usr/lib/python2.7
/usr/lib/python2.7/plat-linux2
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/home/daddona/.local/lib/python2.7/site-packages
/usr/lib/python2.7/site-packages
/usr/lib/python2.7/site-packages/gtk-2.0

As you can see, it seems that the gtk module search path is missing. The search path is specified in the file /usr/lib/python2.7/site-packages/pygtk.pth which is provided by the package python2-gobject2. Can you post the content of pygtk.pth and can you also check if python2-gobject2 package was altered?


About me - github

-- When you have eliminated the impossible, whatever remains, however improbable, must be the truth -- Spock | Sherlock Holmes

Offline

#5 2015-07-29 08:46:29

mahesmohan
Member
From: India
Registered: 2013-06-08
Posts: 12

Re: [SOLVED] Python. No module named gtk

Unfortunately there is no pygtk.pth was missing and I reinstalled python2-gobject2 package which fixed the issue of unable to import gtk module.

Thank you mauritiusdadd

Now running guake brings an error

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/site-packages/guake/main.py", line 28, in <module>
    import gtk
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 40, in <module>
    from gtk import _gtk
ImportError: No module named cairo

Let me google and try to fix it, if not I'll be back right here tongue

After reinstallation of a few packages gauke is up and running.

Last edited by mahesmohan (2015-07-29 09:10:14)

Offline

#6 2015-07-29 09:53:03

mauritiusdadd
Member
From: Benevento, Italy
Registered: 2013-10-27
Posts: 776

Re: [SOLVED] Python. No module named gtk

You're welcome. I also suggest you to use

pacman -Qkk

to check if there are more missing files form other packages.


About me - github

-- When you have eliminated the impossible, whatever remains, however improbable, must be the truth -- Spock | Sherlock Holmes

Offline

#7 2015-07-29 17:00:59

mahesmohan
Member
From: India
Registered: 2013-06-08
Posts: 12

Re: [SOLVED] Python. No module named gtk

That's a new piece of information. Thanks again mauritiusdadd. smile

Offline

Board footer

Powered by FluxBB