Friday, November 26, 2021 [Tweets] [Favorites]

Xcode’s Environmental Pollution

Daniel Jalkut (tweet):

After a lot of trial and error, I came across the strangest observation: if I invoke “xcodebuild” from within my Python-based build script, the warning is emitted. If I invoke it directly from the Terminal, it isn’t. In fact, if I simplify my build script to simply invoking “xcodebuild”, the warning happens. Stranger still? If I change the script from “python3” to just “python”, the warning goes away again.

[…]

Sure enough, the environment variables differed when I ran the script with “python” vs. “python3”.

[…]

That “CPATH” entry for example only exists when invoking the script with python3, and it’s this very environment variable that is creating the unexpected Xcode warnings!

I was perplexed about how or why the version of Python could impact these environment variables, but then I remembered that python3 is bundled in Xcode itself, and the version at /usr/bin/python3 is a special kind of shim binary that directs Apple to locate and run the Xcode-bundled version of the tool. Apparently, a side-effect of this mechanism causes the problematic environment variable to be set!

1 Comment

Confirmed. This is something weird about Apple's bundled Python.

When I run /usr/bin/python3 (which is the Apple version or Python 3.8.9), see the above behavior.

If I run /usr/local/bin/python3 (version 3.9.7, manually installed via the installer on python.org), there is no such problem. On my system, /usr/local/bin appears first on the PATH, so I have never seen this issue.

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment