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.

3
  • did you mis-spell pangocairo ? I just tried it, and it works fine Commented Jun 25, 2014 at 16:52
  • how can I mispell something that I didn't write? :) I just used copy+paste Commented Jun 25, 2014 at 16:59
  • Did you call the file pangocairo.py perhaps? If so don't do that. You are masking the installed module. Commented Jun 25, 2014 at 22:01

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

I called it like that, yes, but renaming it doesn't fix it, therefore I'm downvoting this
@knocte: I added additional advice. Do make sure you removed the pangocairo.pyc file that was left in the directory.
wtf, you were right, solved when I removed the pangocairo.pyc
this makes me realize that I hate python much more than I thought
@knocte: You'll get used to the module namespace issue. There are gotchas like this in every programming language. Python has fewer than most.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.