Simplest way to make Python 3 the default on MacOS
On a fresh MacOS install, Python defaults to version 2. Not ideal. Here I show you the quickest way to make the default Python 3.
1. Install Python 3
Do this via Homebrew, it’s the easiest.
brew install python@3
2. Add /usr/local/bin to your path
Homebrew will add
python3 as an executable in
/usr/local/bin. Add this
directory to your path by running one of the following commands (depending on
your shell preference):
echo 'export PATH=/usr/local/bin:$PATH' > ~/.bashrc echo 'export PATH=/usr/local/bin:$PATH' > ~/.zshrc
3. Symlink python3 to python
python executable is actually Python 2. Try it:
$ which python && python --version /usr/local/bin/python Python 2.X.X
We need to replace this executable with the
python3 location, and this can be
achieved by a symbolic link:
unlink /usr/local/bin/python ln -s /usr/local/bin/python3 /usr/local/bin/python
Now restart your shell, and you should be good to go. Happy coding!
But what about pip?
If you’ve previously installed
pip using an
old version of Python, you should re-install it using the
which now points to
You can do this with the following commands:
cd ~ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py which python && python --version # verify it's python 3 python get-pip.py
Then you can re-install any packages that you installed globally again.
Any questions? Feel free to reach out.