Skip to content

How to set Python 3 as default on a Mac?

Published:Β atΒ 06:16 PM

If you are a Mac OSx user, you will frequently come across installing different packages via terminal. To install python packages, you will need the pip command. By default, Mac OS comes with an older version of python 2.7 due to dependencies. The latest version of packages cannot be downloaded using the pip associated with the old python version. python-image You might be thinking of removing python 2.7 and replacing it with the new one. It is highly recommended not to remove the older version of python as it will affect the functionality of different in-built apps.

Here, you will learn of a simple way to use the latest version of python without removing python 2.7. Install the latest version of python

First things first, you will need the latest version of python. You can download it from the Python website or simply use Homebrew for the installation.

brew install python

You can verify the installation by typing

python -V

Here is the most important part. You can now set up a default alias for the latest version of python. That way, you can enjoy the latest version of python without having to remove the older one.

Go to your shell config file and add an alias. If you use zsh or default bash shell, you can simply create an alias by adding the following line to your config file:

alias python=/usr/local/bin/python3

You will also need to create an alias for pip

alias pip=/usr/local/bin/pip3

You can simply close your terminal and restart it to use the latest version of Python and pip.

You can check where your python and pip are aliased by simply running in your terminal:

which python
which pip

One drawback of this method is that you will need to manually update the config file when there is a newer version of Python 🐍 .