https://stackoverflow.com/questions/6819661/python-location-on-mac-osx
This one will solve all your problems not only for Mac but for every basic shell -> Linux also: TL;DR (you don't have to go over all of it) Let's start by running:
which python3
On Mac you should get:
/usr/local/bin/python3
Now this is a symbolic link, how do you know? Run:
ls -al /usr/local/bin/python3
and you'll get (if you've installed Python w/ Brew):
/usr/local/bin/python3 -> /usr/local/Cellar/python/3.6.4_4/bin/python3
which means that your
/usr/local/bin/python3
is actually pointing to – that's it!:
/usr/local/Cellar/python/3.6.4_4/bin/python3
Longer version (optional): If, for some reason, your
/usr/local/bin/python3
is not pointing to the place you want, which in our case:
/usr/local/Cellar/python/3.6.4_4/bin/python3
just backup it:
cp /usr/local/bin/python3{,.orig}
and run:
rm -rf /usr/local/bin/python3
now create a new symbolic link:
ln -s /usr/local/Cellar/python/3.6.4_4/bin/python3 /usr/local/bin/python3
and now your
/usr/local/bin/python3
is pointing to
/usr/local/Cellar/python/3.6.4_4/bin/python3
Check it out by running:
ls -al /usr/local/bin/python3
I found the easiest way to locate it, you can use
which python
it will show something like this:
/usr/bin/python
[GCC 4.2.1 (Apple Inc. build 5646)]
is the version of GCC that the Python(s) were built with, not the version of Python itself. That information should be on the previous line. For example:
# Apple-supplied Python 2.6 in OS X 10.6
$ /usr/bin/python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
# python.org Python 2.7.2 (also built with newer gcc)
$ /usr/local/bin/python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Items in /usr/bin
should always be or link to files supplied by Apple in OS X, unless someone has been ill-advisedly changing things there. To see exactly where the /usr/local/bin/python
is linked to:
$ ls -l /usr/local/bin/python
lrwxr-xr-x 1 root wheel 68 Jul 5 10:05 /usr/local/bin/python@ -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python
In this case, that is typical for a python.org installed Python instance or it could be one built from source.
Follow
answered Jul 25, 2011 at 19:02
81k1616 gold badges124124 silver badges150150 bronze badges
60
On Mac OS X, it's in the Python framework in /System/Library/Frameworks/Python.framework/Resources
.
Full path is:
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Btw it's easy to find out where you can find a specific binary: which Python
will show you the path of your Python binary (which is probably the same as I posted above).
Follow
answered Jul 25, 2011 at 17:00
9,96944 gold badges3838 silver badges5757 bronze badges
yea i knew that. Its just that I'm confused – I ran the interpreter on /usr/local/bin/ and printed sys.executable. It says /usr/bin/python. but I read the docs and it says that the apple-provided was in /usr/bin/ and the macpython's "A symlink to the Python executable is placed in /usr/local/bin/".
– goh
Well, it makes sense: when you compile the python-executable yourself and move it to, say /Users/John/Downloads/, it'll show you it's placed at /Users/John/Downloads/python. You can run multiple executable next to each other on the same system. AFAIK the one in Python.framework is the primary one though, so you should rely on that one.
– cutsoy
30
Actually, the Apple-supplied Pythons in Mac OS X are in
/System/Library/Frameworks/Python.framework
. Anything in/Library/Frameworks/Python.framework
comes from a third-party install, usually a python.org (or other distributor) installer or if you did a default framework build of Python from source.1
When I run
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
theps aux
output shows me/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
, why is that – I don't see that it's a symlink ? ( Asked this question at AskDifferent )– Zitrax
@Tim Thanks. When I go to /Library/Frameworks/Python.framework/Versions/, I see not 2.7 (which is what I have installed), but an alias file called 'Current', which, when clicked, gives me the error "The operation can't be competed because the original item for 'Current' can't be found."
– Pyderman