ImportError: No module named glib

Peter Otten __peter__ at web.de
Fri Mar 5 06:46:54 EST 2010


Michael Joachimiak wrote:

> I am too new to python.
> If anybody has an idea what to do please help.
> when I use
> 
> import glib
> 
> in my code I get this:
> 
>>>> import glib
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ImportError: No module named glib
> 
> :~$ python -V
> Python 2.6.4
> 
> /usr/lib/libpyglib-2.0-python2.6.so.0.0.0 exists in version
> 2.18.0-0ubuntu2
> 
> :~$ pkg-config glib-2.0 --cflags --libs
> -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include  -lglib-2.0

After the following random walk through my system

$ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import glib
>>> glib.__file__
'/usr/lib/pymodules/python2.6/gtk-2.0/glib/__init__.pyc'

In the above __init__.py:
...
from glib._glib import *
_PyGLib_API = _glib._PyGLib_API

del _glib
...

>>> import sys
>>> sys.modules["glib._glib"]
<module 'glib._glib' from 
'/usr/lib/pymodules/python2.6/gtk-2.0/glib/_glib.so'>
>>>
$ dpkg -S _glib.so
python-gobject: /usr/lib/pyshared/python2.5/gtk-2.0/glib/_glib.so
python-gobject: /usr/lib/pyshared/python2.6/gtk-2.0/glib/_glib.so
$

... I believe that you have to install the python-gobject package.

Peter




More information about the Python-list mailing list