phimuemue
phimuemue

Reputation: 36031

Python finds glib, but not _glib

I try to import glib in Python (2.7) and get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/share/pyshared/glib/__init__.py", line 22, in <module>
    from glib._glib import *
ImportError: No module named _glib

Seems as if glib is found, while _glib is not found.

Has anybody a hint for solving this problem? I'm running Ubuntu and installed python2.7, python-gobject, python-gda, dbus from Ubuntu's package manager.

Upvotes: 3

Views: 5950

Answers (2)

user1998576
user1998576

Reputation: 46

I had this issue.

You can try moving the glib and related folders out of the python2.7 install locations e.g. on ubuntu /usr/shared/pyshared in case these have been installed wrongly.

Then remove and reinstalling the related packages with the platform package manager ...

sudo apt-get remove followed by sudo apt-get install

for ...

python-gobject python-gtk libglib2.0-dev python-cario python-gi

since if they are present in pyshared I found that they were not probably reinstalled

Upvotes: 3

Louis
Louis

Reputation: 2890

I run ubuntu 10.04, with its native python 2.6.6 and GCC 4.4.5, and an "import glib" in python appears to work.

I installed "python-numpy", "python-matplotlib" and "python-pyfits" with the synaptic package manager and nothing else, in particular nothing installed from a more recent version found on the package's site because previous experience learned me this was usually a very bad idea.

But I have NO /usr/share/pyshared/glib/ folder and do not know how you get it. Is this folder on your path or PYTHONPATH ? If yes, try to remove it from the path and retry the "import glib", it is possible that you get some second installation of glib in that place (installed - and maybe needed - by another package).

glib is an interface to the c compiler, so it is used in several places. What is your GCC version ? GTK also makes intensive use of glib. Did you installed "GTK" and "pygtk" from the synaptic or did you did it on the hard way, with all separated little packes to be compiled ? If yes, try to install it from the synaptic.

I mostly think this comes from some installation mix of some python extension somewhere. The radical solution, of course, is to reformat the computer with a fresh O.S., but it's probably something you do not want, so I should try to uninstall all packages python uses, and re-install them from the synaptic.

Hope this helps...

Upvotes: 1

Related Questions