2

If I try to run this example from the cairo website, I get:

AttributeError: 'module' object has no attribute 'cairo_font_map_get_default'

I guess I'm missing some packages? (I'm on Ubuntu 14.04)

However, I try to find the dev packages I would need, and the only answer I found is this, which is recommending something from the GTK2 stack, but if anything , I'm interested in GTK3, not 2.

naveen521kk
  • 140
  • 1
  • 10
knocte
  • 16,941
  • 11
  • 79
  • 125

1 Answers1

5

I strongly suspect you called your Python file pangocairo.py. Don't do that, you are masking the pangocairo library, and are importing your own script file instead.

At best pangocairo is not what you think it is. Verify the path of the module with:

import pangocairo
print(pangocairo.__file__)

to see what file is really being imported. You probably will have to rename this file.

When you do rename the affected file, a pangocairo.pyc byte cache file may be left in the same location, which still will be imported. Make sure you remove that file altogether.

knocte
  • 16,941
  • 11
  • 79
  • 125
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • I called it like that, yes, but renaming it doesn't fix it, therefore I'm downvoting this – knocte Jun 25 '14 at 22:06
  • 1
    @knocte: I added additional advice. Do make sure you removed the `pangocairo.pyc` file that was left in the directory. – Martijn Pieters Jun 25 '14 at 22:06
  • wtf, you were right, solved when I removed the pangocairo.pyc – knocte Jun 25 '14 at 22:10
  • this makes me realize that I hate python much more than I thought – knocte Jun 25 '14 at 22:11
  • @knocte: You'll get used to the module namespace issue. There are gotchas like this in **every** programming language. Python has fewer than most. – Martijn Pieters Jun 25 '14 at 22:12
  • a language that has a gotcha as big like this and hasn't provided at least a better error message, is.... **facepalm** – knocte Jun 25 '14 at 22:13
  • All the info is there; had you posted the full traceback I would have pointed to the filenames in the traceback; these would have clearly shown you were importing the script itself. – Martijn Pieters Jun 26 '14 at 07:36