4

I'm trying to cleanup my system python environment. I've previously installed another python2 instead of the system provided one using Homebrew and I've uninstalled this one.

I thought there should be only one python2 now on my mac. However, which python gives /usr/bin/python and I noticed there is another one in /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python.

Under /usr/bin/ the output of ls -l is

lrwxr-xr-x   1 root   wheel        74 Jul 22  2015 pydoc2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pydoc2.6
lrwxr-xr-x   1 root   wheel        74 Jul 22  2015 pydoc2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc2.7
-rwxr-xr-x   2 root   wheel     58416 Jul 15  2015 python
-rwxr-xr-x   5 root   wheel       925 Sep 10  2014 python-config
lrwxr-xr-x   1 root   wheel        18 Apr  8  2016 python2 -> /usr/bin/python2.7
lrwxr-xr-x   1 root   wheel        75 Jul 22  2015 python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x   1 root   wheel        82 Jul 22  2015 python2.6-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
lrwxr-xr-x   1 root   wheel        75 Jul 22  2015 python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x   1 root   wheel        82 Jul 22  2015 python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x   2 root   wheel     58416 Jul 15  2015 pythonw
lrwxr-xr-x   1 root   wheel        76 Jul 22  2015 pythonw2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6
lrwxr-xr-x   1 root   wheel        76 Jul 22  2015 pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7

So I think it means /usr/bin/python is not a symlink and it is itself a binary. Meanwhile /usr/bin/python2.7 is a symlink of /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7.

Under /System/Library/Frameworks/Python.framework/Versions/2.7/bin/

lrwxr-xr-x  1 root  wheel      7 Jul 22  2015 2to3 -> 2to32.7
lrwxr-xr-x  1 root  wheel      8 Jul 22  2015 2to3-2 -> 2to3-2.7
-rwxr-xr-x  1 root  wheel    288 Sep 10  2014 2to3-2.7
lrwxr-xr-x  1 root  wheel      6 Jul 22  2015 2to32.7 -> 2to3-2
lrwxr-xr-x  1 root  wheel      5 Jul 22  2015 idle -> idle2
lrwxr-xr-x  1 root  wheel      7 Jul 22  2015 idle2 -> idle2.7
-rwxr-xr-x  1 root  wheel    230 Sep 10  2014 idle2.7
lrwxr-xr-x  1 root  wheel      6 Jul 22  2015 pydoc -> pydoc2
lrwxr-xr-x  1 root  wheel      8 Jul 22  2015 pydoc2 -> pydoc2.7
-rwxr-xr-x  1 root  wheel    215 Sep 10  2014 pydoc2.7
lrwxr-xr-x  1 root  wheel      7 Jul 22  2015 python -> python2
lrwxr-xr-x  1 root  wheel     14 Jul 22  2015 python-config -> python2-config
lrwxr-xr-x  1 root  wheel      9 Jul 22  2015 python2 -> python2.7
lrwxr-xr-x  1 root  wheel     16 Jul 22  2015 python2-config -> python2.7-config
-rwxr-xr-x  1 root  wheel  34944 Jul 15  2015 python2.7
-rwxr-xr-x  1 root  wheel   1818 Jul 15  2015 python2.7-config
lrwxr-xr-x  1 root  wheel      8 Jul 22  2015 pythonw -> pythonw2
lrwxr-xr-x  1 root  wheel     10 Jul 22  2015 pythonw2 -> pythonw2.7
-rwxr-xr-x  1 root  wheel  34944 Jul 15  2015 pythonw2.7
lrwxr-xr-x  1 root  wheel      9 Jul 22  2015 smtpd.py -> smtpd2.py
-rwxr-xr-x  1 root  wheel  18681 Sep 10  2014 smtpd2.7.py
lrwxr-xr-x  1 root  wheel     11 Jul 22  2015 smtpd2.py -> smtpd2.7.py

However, it seems /usr/bin/python and /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 are same binary since they both gives

Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

when I ran them.

I'm confused whether these two binary indicate same python interpreter? But why are they two standalone binary files?

jinglei
  • 3,269
  • 11
  • 27
  • 46
  • The `/usr/bin` entry `lrwxr-xr-x 1 root wheel 75 Jul 22 2015 python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7` is a symlink to the one under `/System/...` - They are the same. – metatoaster Feb 12 '18 at 06:07
  • 1
    @metatoaster But `/usr/bin/python` is not a symlink to `/usr/bin/python2.7`? – jinglei Feb 12 '18 at 06:11
  • Possible duplicate of [python location on mac osx](https://stackoverflow.com/questions/6819661/python-location-on-mac-osx) – metatoaster Feb 12 '18 at 07:33

1 Answers1

3

The is part of MacOSX's versioning system. Your actual Python executable is at /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7.

/usr/bin/python is a wrapper which chooses which python version to use based on the version specified in the com.apple.versioner.python.plist property list file and VERSIONER_PYTHON_VERSION environmental variable, amongst others.

Perl works in the same way. It's designed to allow users to choose between the versions of python and perl which come with the operating system, although as of macOS version 10.14.2 (mojave), only one version of each is installed.

If you did have more than one version of Python installed you could change the default version with the following command:

defaults write com.apple.versioner.python Version -string 2.7.10

or

export VERSIONER_PYTHON_VERSION=2.7.10

This is just an example, it assume version 2.7.10 is installed.

The above only applies to programs included in the OS by Apple, not to versions installed via Homebrew or MacPorts, downloaded or compiled yourself.

Sources: http://krypted.com/mac-os-x/perl-control/ and https://gist.github.com/crankycoder/1389144

MJ Walsh
  • 593
  • 6
  • 11