How To Make Python 3.9 Default On Mac

In this tutorial, we will learn how to make Python 3.9 the default Python version on your Mac. Most Mac systems come pre-installed with Python 2.7, which is an older version and no longer supported.

Python 3.9 is the latest version and comes with many new features and performance improvements. We will use brew and pyenv to install and manage different Python versions.

Step 1: Install Homebrew

First, we need to install Homebrew, which is a popular package manager for macOS. It allows us to install and manage different software packages on our system. If you don’t have it installed, open the Terminal application and run the following command:

This command will download and install Homebrew on your system. Once it’s done, verify the installation by running:

Step 2: Install pyenv

Now that we have Homebrew installed, we can use it to install pyenv. pyenv is a Python version manager that allows us to have multiple Python versions installed on our system easily. Run the following command to install pyenv using Homebrew:

After the installation is complete, we need to configure our shell to use pyenv. Add the following lines to your shell configuration file (.bashrc, .bash_profile, or .zshrc):

Now, restart your terminal to apply the changes, or run the following command:

or

Depending on which shell configuration file you edited.

Step 3: Install Python 3.9

With pyenv installed, we can now install Python 3.9. Run the following command to download and compile Python 3.9.7:

Once the installation is complete, we can verify it by running:

This command will list all the Python versions installed on your system. You should see Python 3.9.7 in the list.

Step 4: Set Python 3.9 as the default Python version

Now that Python 3.9 is installed, we can set it as the default Python version for our system. Run the following command to set Python 3.9.7 as the default Python version:

After running this command, run the following command to verify that Python 3.9.7 is set as the default version:

If everything went well, you should see “Python 3.9.7” as the output.

Full Code

The following code snippets were used in this tutorial:

Conclusion

In this tutorial, we learned how to make Python 3.9 the default Python version on a Mac using Homebrew and pyenv. This allows us to use the latest version of Python and take advantage of its new features and performance improvements. Remember that you can use the same process to install and manage other Python versions using pyenv.