PicTex
raw JSON → 2.3.0 verified Sat May 09 auth: no python
PicTex is a Python library for generating images via CSS Flexbox layout. It uses a declarative API to compose elements, supports text shaping via HarfBuzz, Unicode bidirectional text, gradients, and inline spans. Current version 2.3.0 requires Python >=3.9. Releases occur irregularly, with breaking changes in v2.0.0 that renamed many methods.
pip install pictex Common errors
error ImportError: cannot import name 'Canvas' from 'pictex' ↓
cause Installed version is too old (<2.0.0) or PicTex not installed correctly.
fix
Upgrade to latest: pip install --upgrade pictex
error ModuleNotFoundError: No module named 'pictex' ↓
cause PicTex is not installed.
fix
Install: pip install pictex
error AttributeError: 'Canvas' object has no attribute 'add_static' ↓
cause Method renamed in v2.0.0 breakage.
fix
Use canvas.add() or the new positioning methods. See migration guide.
Warnings
breaking v2.0.0 introduced breaking changes: many methods were renamed to match CSS terminology (e.g., add_static was removed, layout changed). Existing code from v1.x will not work without migration. ↓
fix Follow the migration guide at https://github.com/francozanardi/pictex/blob/main/docs/MIGRATION.md
deprecated The v2.0.0 release replaced Skia with HarfBuzz for text shaping. If you were using skia-specific features or relying on Skia fonts, you may need to adjust. ↓
fix Use standard font paths; HarfBuzz handles shaping automatically.
gotcha Text wrapping can behave unexpectedly when no width constraint is set. Floating-point precision may cause false word-wrapping. In v2.1.1 this was fixed, but it's still a good practice to set a width for text elements. ↓
fix Always specify a width on text-containing elements, e.g., Text("...", width=200).
gotcha Inline spans (Span) are new in v2.3.0. They are deeply nestable but properties cascade; forgetting to override a property may lead to unintended inheritance. The note says 'properties cascade down and inherit naturally unless explicitly overridden'. ↓
fix Explicitly set properties on each Span to avoid inheritance surprises.
Imports
- Canvas wrong
from pictex.canvas import Canvascorrectfrom pictex import Canvas - Span wrong
from pictex.text import Spancorrectfrom pictex import Span - RadialGradient wrong
from pictex.gradients import RadialGradientcorrectfrom pictex import RadialGradient
Quickstart
from pictex import Canvas, Text, Rect
canvas = Canvas(200, 100, background_color="white")
canvas.add(Rect(width=50, height=50, background_color="blue"))
canvas.add(Text("Hello, PicTex!"))
image = canvas.render()
image.save("output.png")