This one will solve all your problems not only on Mac but to find it on Linux also ( & every basic shell).
TL;DR (you don't have to go through all the answer - just the 1st half).
LET'S GO
Run in terminal:
which python3
On Mac you should get:
/usr/local/bin/python3
WAIT!!! It's prob 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 (the real location)
/usr/local/Cellar/python/3.6.4_4/bin/python3
That's it!
Longer version (optional): If for some reason, your
/usr/local/bin/python3
is not pointing to the place you want, which is in our case:
/usr/local/Cellar/python/3.6.4_4/bin/python3
just back it up (+cool trick to add .orig suffix to file):
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
Answer from Kohn1001 on Stack OverflowThis one will solve all your problems not only on Mac but to find it on Linux also ( & every basic shell).
TL;DR (you don't have to go through all the answer - just the 1st half).
LET'S GO
Run in terminal:
which python3
On Mac you should get:
/usr/local/bin/python3
WAIT!!! It's prob 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 (the real location)
/usr/local/Cellar/python/3.6.4_4/bin/python3
That's it!
Longer version (optional): If for some reason, your
/usr/local/bin/python3
is not pointing to the place you want, which is in our case:
/usr/local/Cellar/python/3.6.4_4/bin/python3
just back it up (+cool trick to add .orig suffix to file):
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
Videos
I moved from Windows to a MacBook yesterday (runs MacOS 14 Sonoma on Apple Silicon). I'm trying to get Python to work properly on my MacBook but I'm having a hard time figuring it out.
I'm being able to run Python from the terminal but it doesn't run from VSCode. From the terminal (ZSH) too, only python3 ran but not python. To get around that, I followed an online article and added a ~/.zshrc file. I added these two lines to it:
alias python="/usr/bin/env python3" alias pip="/usr/bin/env pip3"
I tried to install a Python package using pip but it hit me with a WARNING: The script normalizer is installed in '/Users/my_username/Library/Python/3.9/bin' which is not on PATH.
So till now I've understood that Python can be installed on Mac in 3 ways:
-
The default inbuilt Python that comes with Mac out of the box.
-
Python installed from the Python website via an installer.
-
Python installed via Homebrew.
I am not being able to figure out the paths where each of these methods install Python. Which method is better for installing? Homebrew or download from the website? And once I have Python using one of the options, how do I make sure that it is the one used over the system Python? If I override the system Python, will there be any issues? How do I get Python to run from VSCode?
My MacOS and command line knowledge is very rudimentary so please correct me if I've said something wrong.
I moved from Windows to a MacBook yesterday (runs MacOS 14 Sonoma on Apple Silicon). I'm trying to get Python to work properly on my MacBook but I'm having a hard time figuring it out.
I'm being able to run Python from the terminal but it doesn't run from VSCode. From the terminal (ZSH) too, only python3 ran but not python. To get around that, I followed an online article and added a ~/.zshrc file. I added these two lines to it:
alias python="/usr/bin/env python3" alias pip="/usr/bin/env pip3"
I tried to install a Python package using pip but it hit me with a WARNING: The script normalizer is installed in '/Users/my_username/Library/Python/3.9/bin' which is not on PATH.
So till now I've understood that Python can be installed on Mac in 3 ways:
-
The default inbuilt Python that comes with Mac out of the box.
-
Python installed from the Python website via an installer.
-
Python installed via Homebrew.
I am not being able to figure out the paths where each of these methods install Python. Which method is better for installing? Homebrew or download from the website? And once I have Python using one of the options, how do I make sure that it is the one used over the system Python? If I override the system Python, will there be any issues? How do I get Python to run from VSCode?
My MacOS and command line knowledge is very rudimentary so please correct me if I've said something wrong.
It's normal to have many python binaries. You can see which is which in /usr/bin with this command:
$ ls -l /usr/bin/python*
You will see several links to different places. The native python is that one, which is in the /System/Library/Frameworks/Python.framework/Versions/2.7/bin/. Note that for OSX 10.9 (and for everything at least until 10.13) this is the python2, not python3. So you can safely remove all the other versions.
What are the other versions which you may have?
- Something downloaded from the official site python.org. It is located in
/Library/Frameworks/Python.framework/Versions/. You can remove whatever in this folder you do not want. Removing the whole folder will completely remove Python including the original system version. - Anaconda distribution is by default located in
/Users/your_user/anaconda3/, but of course you may put in the other place. But if it containsanacondain the path – it's Anaconda distribution. You may remove this folder. - Either
homebreworportversions are in/opt/local/bin/. See the link destination with$ ls -l /opt/local/bin/python*. The best way of removing this is to use built-in commands like uninstall. - Some packages might be in
~/Library/Python/- that's frompip. You may safely remove the entire content of this folder in order to have a "clean"python. - Finally, after you removed all the other versions, do not forget to remove the broken links to binaries, if there are still any.
See also this answer.
you can start by removing any Python Frameworks in /Library/Frameworks and any User Library (like ~/Library/Frameworks). The system one is in /System/Library/Frameworks.
homebrew and macports install under /usr somewhere IIRC. not sure of other places to look, but you should be able to grep for "Python" to find them all.
be aware, if you have installed other software via homebrew that is dependent on Python, you will break it. you may be able to fix it with symbolic links to the system python, however, some software requires Python 3. as of 10.9 the system has Python 2.3-2.7 only.