pythoncairopangopycairopangocairo

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


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.


Solution

  • 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.