Error Importing Glib
Asked Answered
D

1

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?

Deepfry answered 1/7, 2015 at 2:48 Comment(3)
Can you show your code?Longplaying
It throws an error as soon as it gets to the import statement. I've tried using the interactive interpreter, that's where it throws the error.Deepfry
Interesting. Can I ask how you installed glib?Politian
C
9

It works for me with GLib correctly capitalized:

from gi.repository import GLib
Cavitation answered 1/7, 2015 at 3:3 Comment(4)
Well, that works. Odd, I've seen multiple websites spell it with different capitalization saying it works.Deepfry
@Deepfry maybe you confused it with the old style import glib?Cavitation
Maybe the site I copied it from had. I've seen from gi.repository import glib and from gi.repository import GlibDeepfry
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.Cavitation

© 2022 - 2024 — McMap. All rights reserved.