Mapping python to Python 3 on Your Mac

When you install Python 3 on a Mac, it does not update the python command to use Python 3 instead of Python 2. Instead, to run Python 3, you have to use the python3 command. Here’s how to fix this:

First, check your Python version:

Nats-MBP:~ natdunn$ python -V
Python 2.7.15

We want that to say python 3. something.

What shell are you using?

First, determine what shell you are using.

Open Terminal and look at the last character of the prompt. If it’s a dollar sign ($), you’re most likely using bash. If it’s a percentage sign (%), you’re most likely using zsh. You can confirm by running:

echo $SHELL

Update your profile

First, change into your Home directory:

cd ~

Depending on which shell you are using, enter one of the following:

nano .bash_profile

nano .zshrc

This will open the nano editor. If it has content already, scroll to the bottom using your down arrow key.

Add the following line:

alias python=python3

Make sure to save (write out) by pressing Ctrl+O then Enter. Then press Ctrl+X and Enter to exit nano.

Restart Terminal.

Run python -V to see check the version:

Nats-MBP:~ natdunn$ python -V
Python 3.8.3

You’re good to go.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.