Xcode-provided python uses the wrong libdir
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
Bug Description
When using the system python3 (which forwards to the one by Xcode), this line:
https://github.com/PyO3/pyo3/blob/da9da49e771be99d1de229c9b406c4e91cca8a9a/pyo3-build-config/src/impl_.rs#L474
Prints /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib, even when Xcode is installed in a different location, such as /Applications/Xcode_2.app/Contents/Developer/usr/bin/python3.
I suspect a similar problem happens for Command Line Tools.
Steps to Reproduce
- Have Xcode installed (and probably only that, not homebrew or a uv-managed python)
mv /Applications/Xcode.app /Applications/Xcode_2.app- Do either
sudo xcode-select --switch /Applications/Xcode_2.apporexport DEVELOPER_DIR=/Applications/Xcode_2.app/Contents/Developer cargo buildnow fails.
I get the following linker errors:
warning: search path '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib' not found
library 'python3.9' not found
Your operating system and version
macOS 15.7.9
Your Python version (python --version)
Python 3.9.6
Your Rust version (rustc --version)
rustc 1.98.1 (48a229cea 2026-09-01)
Your PyO3 version
0.29.2
How did you install python? Did you use a virtualenv?
Xcode
Additional Info
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pyo3-build-config/src/impl_.rs around line 474 and reproduce with Xcode moved to /Applications/Xcode_2.app or with DEVELOPER_DIR set. Trace how the Xcode-provided Python libdir is derived, then verify that cargo build no longer searches the old Xcode path and that the Python 3.9 library is found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100