1

I am using Python3 on an Ubuntu 12.04 system, and I am writing some small apps to teach myself about using cairo from within Python. In idle3 I find the following:

    >>> import glib
    Traceback (most recent call last):
      File "<pyshell#0>", line 1, in <module>
        import glib
    ImportError: No module named glib

I have used Gtk and cairo on the same setup, and python3-gi and python3-gi-cairo are both installed, and in other respects seem to be working fine. It seems there is something else that is missing, but in spite of several web searches I have not unearthed any clues as to what is wrong here.

Can someone please point me in the right direction?

Bobble
  • 2,791
  • 4
  • 23
  • 30
  • This question is perhaps better suited for [askubuntu](http://askubuntu.com)? – Pedro Romano Nov 11 '12 at 18:07
  • Although I specified 'Ubuntu' in the tags, I have no reason to believe this particular question is necessarily confined to Ubuntu. Hence I asked it here. See also my preferred answer, which does not seem to be unique to Ubuntu. (I can't test this because I do not have a Windows box to hand...) – Bobble Nov 12 '12 at 12:47

1 Answers1

4

For gobject introspection, which is what python3-gi gives you, the proper incantation is this:

 >>> from gi.repository import GLib

For Cairo, use cairo instead of GLib.

In general, at least under Linux, the installed gobject introspection typelibs are installed in /usr/lib/girepository-1.0 (or similar). The name you use to import is derived straightforwardly from the typelib file name.

ergosys
  • 47,835
  • 5
  • 49
  • 70
  • Thanks ergosys, this does indeed solve my problem. I think the code example I was looking at must have been using an earlier version of the binding libraries, hence my confusion. – Bobble Nov 12 '12 at 12:49