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
How do I find the Python 3 path on macOS?
Should I install pip packages into the system Python on macOS?
Why is my python3 path different from the one in the Applications folder?
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.
Modifications to sys.path only apply for the life of that Python interpreter. If you want to do it permanently you need to modify the PYTHONPATH environment variable:
PYTHONPATH="/Me/Documents/mydir:$PYTHONPATH"
export PYTHONPATH
Note that PATH is the system path for executables, which is completely separate.
**You can write the above in ~/.bash_profile and the source it using source ~/.bash_profile
On MAC OS you can simply find the location of python/python3 by using the command which python or which python3. (works for Linux too)
And it should give something like:
For python
/usr/local/bin/python
For python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
Export the path to your bash_profile
In your terminal type
sudo nano ~/.bash_profile
Enter your password and paste the following lines
PYTHONPATH="/Library/Frameworks/Python.framework/Versions/3.9/bin/python3"
export PYTHONPATH
Press control + x to exit, and press y for saving on being asked to save
Press `enter' to return to terminal window
Source it using the following command in terminal, run
source ~/.bash_profile
Path to python3 should be updated now!!
I just solved this problem by installing Python 3.2.2 on my Mac OS X Lion so I thought I would post how I did it in the hopes someone may find it helpful.
Firstly, I agree with shadesandcolour in that you should not modify the default copy of python that came with your mac because there could be scripts that may not work properly when run using the Python 3.0+ interpreter. Having said that, to install that latest Python (3.2.2 at the time of this post), you should first download the Python installer from the official website. Install as per normal. Run the "Update Shell Profile.command" file in /Applications/Python(ver) folder.
After python has been installed, you need to edit your path by typing "sudo nano /etc/paths" at the command line. Next, enter your password when prompted. Next just "cut" the line "/usr/local/bin" and "paste" it BEFORE the occurrence of "/usr/bin". Save the file, close any open terminals and run a new instance of terminal. Now when you type "python" at the command line, the shell will search through /usr/local/bin first and run the latest copy of python.
From my experience, using symlinks along with a properly ordered PATH is the way to have multiple versions of Python coexist in OS X or any other nix I can think of. OS X is just a little bit goofy, but it works the same way.
First get the full picture by running the following commands:
which python
Then:
ls -la /usr/bin/python*
and compare with:
ls -la /usr/local/bin/python*
See where the symlinks are pointing.
Based on the PATH you posted, since /usr/bin comes after /usr/local/bin and the others you are probably using the System python interpreter:
/usr/bin/python
If you installed python3.0 it will likely run as:
/usr/local/bin/python
Now that you know what is pointing where, and what interpreter is being loaded from the PATH, you can make the appropriate changes to the PATH and/or symlinks. You can then use the same techniques to confirm the proper changes.
For more good information about python installation on macOS see dive into python3 and farmdev.