xiaohongshu
xiaohongshu
maturin-debugger
Diagnose and fix maturin build issues for PyO3 Python bindings. Use when encountering problems with maturin develop, missing Python exports, module registration errors, or type stub generation issues. Particularly useful when new PyO3 methods compile but don't appear in Python.
Full skill instructions
Provide systematic debugging workflows for maturin and PyO3 development issues, with particular focus on the known caching problem where new methods compile successfully but don't appear in Python.
Use this skill when encountering:
#[pymethods] functions that compile but don't appear in Python's dir() or hasattr()maturin develop caching issues that persist after cargo clean#[pymodule]Is the issue related to maturin/PyO3?
├─ Yes → Continue with workflow below
└─ No → Exit skill
Can the code compile successfully with `cargo build`?
├─ No → Fix Rust compilation errors first (outside this skill)
└─ Yes → Continue
Does the issue involve new methods/classes not appearing in Python?
├─ Yes → ⚠️ CHECK STEP 0 FIRST (UV + Maturin Conflict) - 90% of issues!
│ Then proceed to "Missing Methods Workflow"
└─ No → Continue
Is it an import error?
├─ Yes → Jump to "Import Debugging Workflow"
└─ No → Jump to "General Diagnostic Workflow"
Before diving into complex debugging, check these in order:
UV + Maturin Conflict (90% of "methods not appearing" issues)
uv run python after maturin develop?Maturin Develop Caching (9% of remaining issues)
Module Registration (1% of remaining issues)
#[pyclass] types?Scenario: New #[pymethods] compile successfully but don't appear in Python.
This is the #1 cause of methods not appearing - Before anything else, verify you're not mixing uv run with maturin builds.
Problem: PyO3/maturin#2314 - UV may reinstall cached packages after maturin builds, causing fresh code to never load.
Symptoms:
hasattr(obj, 'new_method') returns Falsecargo clean + rebuild, old code still loadsUninstalled 1 package in 1ms / Installed 1 package in 2ms when running PythonTHE SOLUTION - Never Mix maturin develop with uv run python:
# ✅ CORRECT WORKFLOW (from Python package directory)
# Step 1: Remove old venv (if troubleshooting)
rm -rf .venv && uv venv
# Step 2: Build wheel (NOT develop)
uv run --with maturin --with patchelf maturin build --release
# Step 3: Install wheel with uv pip
uv pip install ../target/wheels/<package>-*.whl --force-reinstall
# Step 4: Test using venv Python DIRECTLY (not uv run!)
.venv/bin/python -c "from your_module import YourClass"
.venv/bin/python -m pytest tests/
# ❌ WRONG - DO NOT DO THIS:
maturin develop
uv run python # This reinstalls from cache, wiping out your fresh build!
Debugging Checklist:
Check binary contents:
strings .venv/lib/python*/site-packages/your_module/*.so | grep "your_new_method"
Check file timestamps:
ls -lh .venv/lib/python*/site-packages/your_module/*.so
ls -lh src/your_modified_file.rs
# If .so is older than source, it wasn't updated!
Check where Python is loading from:
.venv/bin/python -c "import your_module; print(your_module.__file__)"
Nuclear option - fresh venv:
rm -rf .venv
uv venv
uv run --with maturin maturin build --release
uv pip install ../target/wheels/*.whl
.venv/bin/python # Test with venv Python directly
Key Rules:
maturin build + uv pip install + .venv/bin/pythonuv run python after maturin operations--force-reinstall actually reinstalls with uvIf this solves the issue, STOP HERE. Otherwise, continue to Step 1.
Run the verification script to check if all #[pyclass] types are registered:
python scripts/verify_module_registration.py
Expected output: Script reports all classes are registered, or lists missing registrations with fix suggestions.
If classes are missing from registration:
#[pymodule] function:
#[pymodule]
fn your_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<YourMissingClass>()?;
Ok(())
}
uv run --with maturin maturin developIf all classes are registered, proceed to Step 2.
This is the most common cause of missing methods. maturin develop has a known caching bug (PyO3/maturin#381) where new methods don't export properly.
Solution - Full Rebuild Sequence:
# From the Python package directory
cargo clean -p <package-name>
uv run --with maturin --with patchelf maturin build --release
uv pip install target/wheels/<package-name>-*.whl --force-reinstall
Replace <package-name> with the actual Rust package name from Cargo.toml.
# Test that the class and methods are accessible
import your_module
print('YourClass' in dir(your_module)) # Should be True
from your_module import YourClass
instance = YourClass()
print(hasattr(instance, 'your_new_method')) # Should be True
If still failing:
#[pyclass] and #[pymethods] are in the same Rust filepub if neededreferences/maturin_best_practices.md for additional edge casesScenario: ImportError or ModuleNotFoundError when trying to import.
python scripts/diagnose_maturin.py <module_name> [ExpectedClass1] [ExpectedClass2]
Example:
python scripts/diagnose_maturin.py pubmed_client Client PubMedClient SearchQuery
Script checks:
.so and .whl files).so submoduleIf no build artifacts found:
uv run --with maturin maturin develop
If .so file exists but import fails:
module-name in pyproject.toml matches expected import pathpython --version)uv pip list | grep <package>If module imports but classes are missing:
Python caches imported modules. After rebuilding:
# Option 1: Restart Python interpreter (recommended)
exit() # then restart
# Option 2: Use importlib.reload()
import importlib
import your_module
importlib.reload(your_module)
For issues not covered above, follow this systematic approach:
# Clean build from scratch
cargo clean -p <package-name>
uv run --with maturin maturin develop --release
# Verify compilation succeeded
echo $? # Should output: 0
python scripts/diagnose_maturin.py <module_name>
Review all sections of the output for anomalies.
Check that the package structure matches expectations:
# From the Python package directory
tree -L 3 target/wheels # Check .whl structure
unzip -l target/wheels/*.whl # Inspect .whl contents
Expected structure:
your_package/
├── __init__.py
├── your_module.cpython-*.so
└── py.typed
Test progressively from lowest to highest level:
# Level 1: Import .so directly
import your_package.your_module as so
print(dir(so))
# Level 2: Import package
import your_package
print(dir(your_package))
# Level 3: Import specific class
from your_package import YourClass
print(dir(YourClass))
# Level 4: Instantiate and use
instance = YourClass()
print(hasattr(instance, 'expected_method'))
Identify at which level the failure occurs, then investigate that specific layer.
Scenario: Type checking fails or IDE autocomplete doesn't work.
# From the Python package directory
cargo run --bin stub_gen
# Copy to correct location (adjust path as needed)
cp your_package/your_module.pyi your_module.pyi
# Run mypy on tests
uv run mypy tests/ --strict
# If errors occur, compare stub with runtime:
python -c "from your_module import YourClass; print(dir(YourClass))"
# vs.
grep "class YourClass" your_module.pyi -A 20
If stubs don't match runtime:
#[gen_stub_pyclass] and #[gen_stub_pymethods] macros are appliedPyStubType (see references/maturin_best_practices.md)uv run --with maturin maturin develop
uv run pytest tests/
uv run --with maturin maturin build --release
cargo clean
rm -rf target/
uv pip uninstall <package-name>
uv run --with maturin --with patchelf maturin build --release
uv pip install target/wheels/<package-name>-*.whl --force-reinstall
# Check what's installed
uv pip show <package-name>
# List package contents
python -c "import <module>; print(dir(<module>))"
# Check .so location
python -c "import <module>; print(<module>.__file__)"
diagnose_maturin.py: Comprehensive diagnostic tool that checks build artifacts, module exports, and suggests rebuild steps. Run with module name and expected class names.
verify_module_registration.py: Scans Rust source files to verify all #[pyclass] types are registered in the #[pymodule] function. Reports missing registrations with exact fix code.
maturin_best_practices.md: Detailed reference covering the known maturin caching issue, module registration rules, type stub generation, common pitfalls, and debugging strategies. Load this into context for deep-dive troubleshooting or when implementing new PyO3 bindings.
After following these workflows, verify:
dir(module)hasattr(instance, 'method') returns True for all methodsfrom module import ClassNamemypy passes)If any of these fail, revisit the appropriate workflow above or consult references/maturin_best_practices.md for edge cases.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience