How to Install Python 3 on Mac M1 (with pyenv)

Open up your terminal, because we will do everything with command line. Don’t be scared. Just follow the steps. And it will be done in no time. Very easy and straightforward.

1. Install Homebrew

/bin/bash -c "$(curl -fsSL"

You might be prompted to install command line tools for Xcode, and it will take a few moment to download and install them.

After the installation is completed, you need to set the PATH so that you can run homebrew with the command brew from your terminal. If your homebrew is installed successfully it will show you how to do it. Just follow the steps or you can just copy paste the commands.

Follow the steps to set up the PATH

2. Install pyenv and python 3

If you run pyenv versions it will show you the installed python in your system.
Here is how to set the python 3.10.2 as the default:
- pyenv global 3.10.2
Or if you want to set it run locally in the current folder:
- pyenv local 3.10.2

Now, run python on your terminal. You will notice that you are still running python 2.7, right? It is because you still need to set the PATH so that pyenv can run properly. Type this command:

PATH=$(pyenv root)/shims:$PATH 

Now, run python again! It has changed to python 3.10 right? But if you close the terminal and rerun python it will be back to default python 2.7. Why? Because, you need to set the PATH permanently. Here is how:

echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc

Done! Easy right? Now you can run any python version in your Mac.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adhi Setyatuhu

A Kotlin android developer and a full stack web developer (familiar with Django) based in Indonesia. Interested in remote jobs.