Overview

Installing

Installing Pango, GLib, FFI

pangocffi depends on Pango, GLib, and libffi being installed.

  • On Mac OS, this is as easy as installing homebrew and then running:

    brew install pkg-config
    brew install libffi
    brew install pango
    brew install glib
    
  • On Linux, these packages are usually installed as part of the base OS.

  • On Windows, if you are using a 64-bit Python, you can use this binary installer to install GTK 3. Use python --version --version to check whether you’re running 32-bit or 64-bit Python.

Feel free to contribute a guide for how to install these dependencies on other systems.

Installing pangocffi

Install with pip:

pip install pangocffi

Note: Python versions < 3.8 are not supported.

Importing pangocffi

The module to import is named pangocffi, however you are welcome to alias the module as pango:

import pangocffi as pango

pangocffi will dynamically load Pango, GLib, and GObject as a shared library upon importing. If it fails to find it, you will see an exception like this:

OSError: dlopen() failed to load pango: pango / pango-1 / ...

If Pango, GLib, or GObject are not installed as a shared library, pangocffi supports specifying a path via environment variables respectively: PANGO_LOCATION, GLIB_LOCATION, GOBJECT_LOCATION.

Basic usage

pangocffi on its own is not that useful, since it depends on a Pango FontMap being declared against the Pango Context. FontMap instances can only be retrieved from libraries such as PangoCairo, PangoXft, PangoFT2, PangoWin32 (See gnome’s documentation Rendering with Pango for a list of rendering engines).

See pangocairocffi for bindings that allow you to render pango objects with cairo.