In this tutorial, I’ll show you how to update your Mac’s default version of Python from 2.x to 3.x.
If Python 3.X is already installed on your system, even if it’s not the default version, then you should be able to run version 3.X using the
python3 command in your Terminal. But in this tutorial, I’ll be showing you how you can run version 3.X using the default
Step 0: Install Homebrew
Homebrew is a very popular package manager for macOS. If you don’t already have it installed, you can install it by running this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 1: Install Python with Homebrew
This command will Python 3.
brew install python
Next, we’ll check the symlinks for Python 3.x. A symlink or a Symbolic Link is simply enough a shortcut to another file.
ls -l /usr/local/bin/python*
This should output something like the following:
Look at the first line. It shows default
python being symlinked to the brew installed
python3. If it does not show this exactly, then set it as the default
python symlink run the following:
ln -s -f /usr/local/bin/python3 /usr/local/bin/python
You should probably run this command just to be sure. Run
ls -l /usr/local/bin/python* again and make sure you have the desired output.
Step 3: Verify Python 3.X install
Run the following command to see which executable Python binary will launch when you issue a
python command to the shell:
The output should be this:
Finally, check if the default Python version has changed:
The terminal should output the newest version of Python 3.x. For me, it is
That’s it! Hope this helps.