9 hours ago · Tech · hide · 0 comments

Today I learned how to setup a Rust project that can be called from Python with PyO3 and maturin through uv. When you follow the PyO3 getting started guide to create a simple Rust project that can be called from Python, the instructions you get assume you'll use a global Python installation to create a virtual environment and to install maturin into it. You can use uv through maturin, but if your project also has a Rust binary, things may break. When you run a command like cargo run, cargo will see the dependency on PyO3 and it will then look for a Python installation. If you have no global Python installations — because you do everything through uv — or if your global installations aren't setup exactly like a vanilla, default installation, PyO3 might fail. The fix is simple. In .cargo/config.toml add the environment variable PYO3_PYTHON that points to the Python inside your virtual environment: # .cargo/config.toml [env] PYO3_PYTHON = { value = ".venv/bin/python", relative = true }…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.