Skip to content

fix(macos): make matching python3-config available in build/test venvs - #2922

Merged
henryiii merged 4 commits into
pypa:mainfrom
henryiii:fix/macos-python3-config
Jul 24, 2026
Merged

henryiii merged 4 commits into
pypa:mainfrom
henryiii:fix/macos-python3-config

Conversation

@henryiii

@henryiii henryiii commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Problem

On macOS, cibuildwheel builds and tests inside a virtualenv and only adds the venv's bin directory to PATH. Virtualenvs don't contain python3-config, so builds that invoke it (for include dirs / link flags) pick up an unrelated one from elsewhere on PATH — typically the system or Homebrew Python — producing broken wheels or ABI mismatches.

Fix

As suggested in review, the base interpreter's bin directory is added to PATH right after the venv's (POSIX only), for both build and test venvs. The matching python3-config/python3.X-config is then found first, and the same holds for anything else shipped next to the base interpreter (e.g. pypy3-config, graalpy3-config). The venv itself is not modified, and its bin still comes first, so python/pip continue to resolve to the venv.

Callers that need stricter isolation are unaffected: iOS rewrites PATH wholesale after venv creation, and Linux builds don't use this code path.

Closes #2021

henryiii added 2 commits June 16, 2026 22:24
Virtualenvs do not contain a python3-config (or versioned
python{X.Y}-config) script, and cibuildwheel only puts the venv bin
directory on PATH. The python.org framework builds ship these scripts
next to the base interpreter, but that directory is never added to PATH,
so C/C++ extensions that invoke python3-config picked up an unrelated
(system/Homebrew) python3-config, producing broken or ABI-mismatched
wheels.

After creating the venv on POSIX platforms, symlink the base
interpreter's python*-config scripts into the venv bin so the correct
one is found first on PATH. Interpreters without such a script (PyPy,
GraalPy, some uv-managed builds) are handled gracefully and never fail
the build.

Assisted-by: ClaudeCode:claude-opus-4.8
Fixes ruff (ANN/TC) and mypy (no-untyped-def) failures in CI.

Assisted-by: ClaudeCode:claude-opus-4.8
@henryiii
henryiii force-pushed the fix/macos-python3-config branch from 4b8d3a5 to 968ce48 Compare June 17, 2026 02:25
Refactor _symlink_python_config_scripts docstring to clarify behavior regarding linking python-config scripts.
@henryiii
henryiii marked this pull request as ready for review June 30, 2026 18:45
@mayeut

mayeut commented Jul 4, 2026

Copy link
Copy Markdown
Member

if we aim to fix this, should a symlink be added or do we want to add the base python bin folder to the PATH instead (right after the venv one) ?
IMHO, adding to PATH seems more natural as it's likely what would be happening on a dev local setup rather than tweaking the virtual environment.

@agriyakhetarpal

Copy link
Copy Markdown
Member

If pypy3-config and graalpy3-config do exist (based on the AI description at least) I think we should similarly match for them and include them for consistency, otherwise it just becomes yet another case where our builds across interpreters are different from each other (and perhaps something a later AI review will flag).

@joerick

joerick commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

should a symlink be added or do we want to add the base python bin folder to the PATH instead

Nice idea! It feels a bit less hacky than modding the venv IMO.

Per review, expose the base interpreter's bin directory on PATH right
after the venv's, rather than symlinking python*-config scripts into
the venv. This also covers pypy3-config/graalpy3-config and anything
else shipped next to the base interpreter, and applies to both build
and test venvs.

Assisted-by: ClaudeCode:claude-fable-5
@henryiii

henryiii commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

🤖 AI text below 🤖

Switched to the PATH approach suggested above: activate_virtualenv now places the base interpreter's bin directory right after the venv's on PATH, instead of symlinking config scripts into the venv. Since the whole directory is exposed, this also covers pypy3-config/graalpy3-config (@agriyakhetarpal's consistency point) without special-casing. Windows is skipped. Tests rewritten accordingly, and the PR description is updated.

@henryiii

Copy link
Copy Markdown
Contributor Author

Could I get a review? Does a thumbs up count? :)

@agriyakhetarpal agriyakhetarpal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about holding off on this; this LGTM – it's just been conference season and I haven't been around lately :)

@henryiii
henryiii merged commit 03cbe93 into pypa:main Jul 24, 2026
45 checks passed
@henryiii
henryiii deleted the fix/macos-python3-config branch July 24, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: venvs lacking python3-config causes some builds to fail

4 participants