Set PYO3_BASE_PYTHON to the stable base interpreter path#3216
Open
alex wants to merge 1 commit into
Open
Conversation
When a project is built by a PEP 517 frontend with build isolation, the frontend creates a randomly-named temporary virtualenv and maturin points PYO3_PYTHON inside it. Because pyo3-build-config registers rerun-if-env-changed=PYO3_PYTHON, the ephemeral path defeats cargo's build cache and forces recompilation of the pyo3 crates on every build, even when the underlying interpreter is identical. maturin now additionally exports PYO3_BASE_PYTHON pointing at the stable base interpreter path (sys._base_executable). pyo3 versions that support it prefer it over PYO3_PYTHON and don't trigger rebuilds when only PYO3_PYTHON changes, keeping the build cache warm. Older pyo3 versions simply ignore the variable, and PYO3_PYTHON is still set to the venv path for build scripts that rely on it. See PyO3/pyo3#6113 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
messense
approved these changes
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a project is built by a PEP 517 frontend with build isolation, the frontend creates a randomly-named temporary virtualenv and maturin points
PYO3_PYTHONinside it. Because pyo3-build-config registersrerun-if-env-changed=PYO3_PYTHON, the ephemeral path defeats cargo's build cache and forces recompilation of the pyo3 crates on every build, even when the underlying interpreter is identical.maturin now additionally exports
PYO3_BASE_PYTHONpointing at the stable base interpreter path (sys._base_executable, as reported by the interpreter probe). pyo3 versions that support it (PyO3/pyo3#6114) prefer it overPYO3_PYTHONand don't trigger rebuilds when onlyPYO3_PYTHONchanges, keeping the build cache warm across isolated builds. Older pyo3 versions simply ignore the variable, andPYO3_PYTHONis still set to the venv path for build scripts that rely on it (e.g. cryptography, pydantic-core).The variable is only set when the reported base executable actually exists on disk, since it takes precedence over
PYO3_PYTHONon the pyo3 side. This is orthogonal to the existingMATURIN_PEP517_USE_BASE_PYTHONopt-in, which swaps the interpreter entirely (and is unchanged).Refs PyO3/pyo3#6113
🤖 Generated with Claude Code