ManimPango
ManimPango provides Python bindings for the Pango text layout library, specifically designed to integrate with the Manim animation engine for advanced text rendering. It allows Manim users to leverage Pango's rich text features, font handling, and internationalization capabilities. The current version is 0.6.1, and the library is actively maintained with frequent minor releases addressing Python version compatibility, OS-specific build issues, and Pango library updates.
Common errors
-
ModuleNotFoundError: No module named 'manimpango'
cause The manimpango package is not installed in your current Python environment.fixRun `pip install manimpango` to install the library. -
Pango-CRITICAL **: no PangoFontMap currently set
cause This error often indicates that the underlying Pango library or its initialization failed, usually due to missing system dependencies or an environment issue.fixOn Linux, ensure system Pango and Cairo development libraries are installed (e.g., `sudo apt-get install libpango1.0-dev libcairo2-dev`). Ensure your environment variables are correctly set if you're using a custom Pango installation. -
TypeError: FontDescriptor() takes no arguments
cause This specific error string is highly unlikely for current versions, but similar TypeErrors might occur if you are calling FontDescriptor from an alpha `1.0.0a` version which had a breaking API rewrite or using an outdated tutorial.fixEnsure you are using the `0.x.x` stable API for `FontDescriptor` which expects a string like 'Family Style Weight Size'. Consult the latest documentation for `manimpango` 0.x.x. -
ERROR: Could not find a version that satisfies the requirement manimpango (from versions: none) ERROR: No matching distribution found for manimpango
cause Your Python version is too old for the available `manimpango` distributions on PyPI, or your operating system/architecture is not supported by the pre-built wheels.fixEnsure you are using Python 3.8 or newer. If on macOS, ensure you are on 10.13+ for recent versions. If on Linux, you might need to ensure system dependencies are in place and try installing from source, or check if specific distributions exist for your environment.
Warnings
- breaking ManimPango dropped support for Python 3.7 in version 0.4.4. Installations on Python 3.7 or older will fail.
- breaking Starting with v0.6.1, ManimPango wheels for macOS require macOS 10.13 (High Sierra) or newer due to an upgrade in the bundled Pango library version. Users on older macOS versions may encounter installation or runtime errors.
- gotcha While ManimPango wheels for Windows and macOS statically link Pango, Linux users (or those installing from source) still require system-level Pango and Cairo libraries to be installed. Missing these can lead to build or runtime errors.
- gotcha The `register_font` API on Windows received updates in v0.6.0. If you were using `register_font` on Windows with a version prior to 0.6.0, you might need to adjust your calls.
Install
-
pip install manimpango
Imports
- FontDescriptor
from manimpango import FontDescriptor
- list_fonts
from manimpango import list_fonts
- register_font
from manimpango import register_font
- PangoUtils
from manimpango import utils
from manimpango import PangoUtils
Quickstart
from manimpango import FontDescriptor, list_fonts, register_font
import os
print("Available fonts (first 5):")
# In a real scenario, this might return hundreds of fonts.
# We limit for demonstration.
for font_name in list_fonts()[:5]:
print(f"- {font_name}")
# Create a font descriptor (Pango uses 'family style weight size')
try:
descriptor = FontDescriptor("Arial Bold 16")
print(f"\nSuccessfully created FontDescriptor for: {descriptor.family}, style={descriptor.style}, weight={descriptor.weight}, size={descriptor.size}")
except Exception as e:
print(f"\nError creating FontDescriptor: {e}")
# Example of how you would register a font (requires an actual font file path)
# For a runnable quickstart, we'll just demonstrate the call without a real file.
# font_file_path = os.environ.get('MANIMPANGO_CUSTOM_FONT_PATH', '/path/to/your/custom_font.ttf')
# if os.path.exists(font_file_path):
# register_font(font_file_path)
# print(f"Registered font from {font_file_path}")
# else:
# print(f"(Skipping font registration: custom font file not found at {font_file_path})")