How to set Python 3 as default on a Mac?
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.
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 internet or simply use Homebrew for the installation.
brew install python
You can verify your installation by typing
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:
You will also need to create an alias for pip
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 pythonwhich 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 🐍 .