Hacker News new | ask | show | jobs
by teilo 2044 days ago
It's in the base OS actually.
1 comments

Nope. Python2 is inbox, but Python3 redirects to the Xcode/developer tools copy.

  % sw_vers
  ProductName: macOS
  ProductVersion: 11.1
  BuildVersion: 20C5048k
  % ls /Library/Python/                  
  2.7
  % ls /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/
  Headers  Python3  Resources Versions
  % ls /System/Library/Frameworks/Python.framework/
  Python  Resources Versions
Ok. Well, I don't have the Xcode command line tools installed. This is what I see:

  % ls -l /usr/bin/python*
  lrwxr-xr-x  1 root  wheel      75 Jan  1  2020 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
  lrwxr-xr-x  1 root  wheel      82 Jan  1  2020 /usr/bin/python-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
  lrwxr-xr-x  1 root  wheel      75 Jan  1  2020 /usr/bin/python2 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
  lrwxr-xr-x  1 root  wheel      75 Jan  1  2020 /usr/bin/python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
  lrwxr-xr-x  1 root  wheel      82 Jan  1  2020 /usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
  -rwxr-xr-x  1 root  wheel  137536 Jan  1  2020 /usr/bin/python3
  lrwxr-xr-x  1 root  wheel      76 Jan  1  2020 /usr/bin/pythonw -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
  lrwxr-xr-x  1 root  wheel      76 Jan  1  2020 /usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7

  % ls -l /usr/bin/pip*
  -rwxr-xr-x  1 root  wheel  137536 Jan  1  2020 /usr/bin/pip3
I had assumed that /usr/bin/python3 was part of the system, since it is not a symlink. But then when I do this, I see it is indeed hitting Xcode:

   % /usr/bin/python3
  objc[12852]: Class AMSupportURLConnectionDelegate is implemented in both ?? (0x20ab7e7a0) and ?? (0x1143782b8). One of the two will be used. Which one is undefined.
  objc[12852]: Class AMSupportURLSession is implemented in both ?? (0x20ab7e7f0) and ?? (0x114378308). One of the two will be used. Which one is undefined.
  Python 3.8.2 (default, Oct  2 2020, 10:45:41)
  [Clang 12.0.0 (clang-1200.0.32.27)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import os
  >>> print(os.environ['PYTHONPATH'])
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/os.py", line 675, in __getitem__
      raise KeyError(key) from None
  KeyError: 'PYTHONPATH'
So Xcode is definitely involved.

EDIT: So I uninstalled Xcode. /usr/bin/python3 is there, but it is clearly a stub file of some sort. If you run it without Xcode or Xcode command line tools installed, you get a popup to install the command line tools. So python3 is not part of the system, but the stubs for it are. Thanks for the patience.

Even more interesting, if you have Xcode, but not the command line tools, the stub launches Python3.8 from the Xcode installation. Once you install the command line tools, it then switches to launching that version. Presumably this is all because of the read-only system volume.