pip install maturin$env:PYO3_USE_ABI3_FORWARD_COMPATIBILITY = "1"
maturin build --releaseexport PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
maturin build --releasepip install target/wheels/raypy*.whlpython examples.pyFor development, use maturin develop instead of building wheels:
# Windows
$env:PYO3_USE_ABI3_FORWARD_COMPATIBILITY = "1"
maturin develop
# Linux/macOS
export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
maturin developThis allows you to edit raypy.py and see changes immediately without rebuilding.
This environment variable enables the ABI3 stable API, which:
- Builds wheels compatible with multiple Python versions
- Reduces binary size
- Simplifies distribution
- Maturin: Builds PyO3 extension modules and packages them as wheels
- Cargo: Manages Rust dependencies and compilation
- Profile: Release mode with:
opt-level = 3: Maximum optimizationlto = true: Link-time optimizationcodegen-units = 1: Better optimization (slower build)
- Ensure you've installed the wheel:
pip install target/wheels/raypy*.whl - Verify the wheel file exists after building
- Update Rust:
rustup update - Update maturin:
pip install --upgrade maturin - Check Python version compatibility (3.8+)
- Use
sudo pip install ...or use a virtual environment (recommended)
# test_build.py
from raypy import boost
@boost
def double(n):
return n * 2
result = double([1, 2, 3, 4, 5])
print(result) # Should print [2, 4, 6, 8, 10]Run with: python test_build.py