skia-pathops: Skia Path Operations for Python
skia-pathops is a Python library that provides access to boolean operations on 2D vector paths using Google's Skia graphics library. It's currently at version 0.9.2, seeing relatively frequent updates that often align with upstream Skia library changes or Python version support.
Common errors
-
ERROR: Could not find a version that satisfies the requirement skia-pathops (from versions: none)
cause Your Python version is too old for the latest `skia-pathops` releases, or no wheel is available for your platform/Python combination.fixUpgrade Python to 3.10 or newer. Check `skia-pathops` PyPI page for supported Python versions and platforms. If you need older Python, `pip install 'skia-pathops<0.9.0'` (for 3.8/3.9) or `'skia-pathops<0.8.0'` (for 3.7). -
ModuleNotFoundError: No module named 'skia_pathops'
cause The package `skia-pathops` was either not installed, or installed in a different Python environment, or there's a typo in the import statement.fixEnsure you've run `pip install skia-pathops` in your active environment. Verify the import is `from skia_pathops import ...`. -
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
cause You are on Windows and `pip` is attempting to build `skia-pathops` from source because no pre-built wheel is available for your specific Python version/architecture. Building C extensions requires C++ compilers.fixInstall the 'Desktop development with C++' workload via the Visual Studio Installer (Community Edition is free), or specifically the 'Microsoft C++ Build Tools'. Alternatively, ensure your Python version has an available wheel, or use the `BUILD_SKIA_FROM_SOURCE=0` approach if you have a pre-built Skia library.
Warnings
- breaking Python 3.8 and 3.9 support was dropped in `v0.9.0`. Users on these Python versions must either upgrade their Python environment or pin to an older `skia-pathops` version.
- breaking Python 3.7 support was dropped in `v0.8.0`. Users on Python 3.7 must upgrade their Python environment or use an older `skia-pathops` version.
- gotcha When building from source, `skia-pathops` typically bundles and compiles `libskia`. To use a system-installed or externally compiled `libskia` instead, you must set the `BUILD_SKIA_FROM_SOURCE=0` environment variable.
- breaking The `PathPen` interface's `curveTo` and `qCurveTo` methods changed to support a variable number of points, aligning with the fontTools BasePen protocol. This can break custom `Pen` implementations.
Install
-
pip install skia-pathops
Imports
- Path
from skia_pathops import Path
- PathOp
from skia_pathops import PathOp
- OpBuilder
from skia_pathops import OpBuilder
Quickstart
from skia_pathops import Path, PathOp, OpBuilder
# Create two simple paths
path1 = Path()
path1.moveTo(0, 0)
path1.lineTo(100, 0)
path1.lineTo(100, 100)
path1.lineTo(0, 100)
path1.close()
path2 = Path()
path2.moveTo(50, 50)
path2.lineTo(150, 50)
path2.lineTo(150, 150)
path2.lineTo(50, 150)
path2.close()
# Perform a union operation
builder = OpBuilder()
builder.op(path1, path2, PathOp.UNION)
union_path = builder.resolve().pop() # resolve returns a list of paths
print(f"Original path 1 contour count: {len(path1.getContours())}")
print(f"Original path 2 contour count: {len(path2.getContours())}")
print(f"Union path contour count: {len(union_path.getContours())}")
# You can inspect the points of the resulting path (simplified output)
first_contour_points = union_path.getContours()[0].points
print(f"First contour points (first 3): {first_contour_points[:3]}")