How to install Python on macOS

ZeroesAndOnes
3 min readJan 25, 2022

In this article I will demonstrate how to install Python 3.10.1 on macOS

1 — Install Homebrew

Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s operating system, macOS, as well as Linux.

To install Homebrew follow these steps:

  1. Open a Terminal
  2. In your Terminal type the following command and hit enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

3. Follow the instruction in your terminal

Once Homebrew has been installed successfully we will need to install ‘pyenv’.

2 — Install pyenv

pyenv lets you easily switch between multiple versions of Python. It’s simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.

In the Terminal type the following command to install pyenv:

brew install pyenv

The installation of pyenv might take few minutes to complete. Once the installation is complete you will then be able to install any Python version you would like.

3 — Use pyenv to Install Python or Update Your Python Version

To install Python 3.10.1 you will need to run the following command in the Terminal:

pyenv install 3.10.1

The process will also take few minutes to complete. Once the installation is complete you will see this in your terminal:

4 — How to Set Up Your macOS PATH for pyenv

We will need to update our .bash_profile in Bash (which is installed in MacOS by default) to set the PATH for pyenv.

In the terminal type the following commands and then press enter:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile

Then you will want to add pyenv Init to your terminal. To do that you will need to run this command:

--

--