8

When trying to import glib in python 3 using from gi.repository import glib, I get an error saying:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2135, in _find_spec
AttributeError: 'DynamicImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/gi/importer.py", line 53, in find_module
    'introspection typelib not found' % namespace)
ImportError: cannot import name glib, introspection typelib not found

I installed all the python glib/dev packages using apt-get on Ubuntu 14.04. Attempting to import the module in python 2 says the module doesn't exist.

How do I fix this?

Kookerus
  • 506
  • 2
  • 7
  • 18

1 Answers1

9

It works for me with GLib correctly capitalized:

from gi.repository import GLib
Dan Getz
  • 8,774
  • 6
  • 30
  • 64
  • Well, that works. Odd, I've seen multiple websites spell it with different capitalization saying it works. – Kookerus Jul 01 '15 at 03:05
  • @Kookerus maybe you confused it with the old style `import glib`? – Dan Getz Jul 01 '15 at 03:12
  • Maybe the site I copied it from had. I've seen `from gi.repository import glib` and `from gi.repository import Glib` – Kookerus Jul 01 '15 at 03:14
  • 1
    A quick Google search shows me lots of `from gi.repository import Glib` and `from gi.repository import GLib as glib`. Easy to confuse, anyway. – Dan Getz Jul 01 '15 at 03:15