PyO3 / PyO3/pyo3

Xcode-provided python uses the wrong libdir

Open
#6,415 2 comments 0 reactions 0 assignees View on GitHub

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
  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:

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.