#6415·pyo3

Xcode-provided python uses the wrong libdir

Author: madsmtmCreated Sep 14, 2026Updated Sep 15, 2026

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

  1. Have Xcode installed (and probably only that, not homebrew or a uv-managed python)
  2. mv /Applications/Xcode.app /Applications/Xcode_2.app
  3. Do either sudo xcode-select --switch /Applications/Xcode_2.app or export DEVELOPER_DIR=/Applications/Xcode_2.app/Contents/Developer
  4. cargo build now fails.

I get the following linker errors:

bash
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