Easily install Python using Pyenv on your M1 Mac(Apple Silicon)

Devesh Surve
3 min readJan 9, 2022

--

We all love the speed and snappiness of M1, and Python of course needs no introduction. However, by default, the python version it ships with is python2.

Here’s how to check the same :

Now, Let’s install pyenv to manage multiple versions of Python. Just like any other thing in life, there are multiple ways to install pyenv on your mac.

Today we shall be taking a look at the simple method using git, all in 8 simple steps. So without further ado, let’s get started.

Git Method

Step 1: Clone the pyenv folder to your local home

$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ cd ~/.pyenv && src/configure && make -C src

Step 2: Edit your zhrc file and add the following

$ vi ~/.zshrcexport PYENV_ROOT="$HOME/.pyenv" 
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"

Step 3: Restart your terminal. Now pyenv should be activated and you can start to install some Python.

Step 4: Here’s how your system should look right about now

Step 5: Now, as per the recommendations given by pyenv suggests that before installing any version of Python, we need a Python build environment for Mac, so we first install Xcode Command Line Tools

$ xcode-select --install

Step 6: Now, now we install brew dependencies which are required. Note : This might take a while.

$ brew install openssl readline sqlite3 xz zlib

Step 7: Finally we install python 3.7 on our Macos using the following command

$ pyenv install 3.7.10

Step 8: Verfication Time !!

List all Python versions managed by pyenv:$ pyenv versions
* system (set by /Users/squademy/.pyenv/version)
3.7.10

Set the default python to 3.7.10, cause that's what I want when typing python on the terminal

$ pyenv global 3.7.10 $ python --version 
Python 3.7.10

Verify pyenv shims is activated on the PATH:

$ type -a python
python is /Users/squademy/.pyenv/shims/python
python is /usr/bin/python

$ which python
/Users/squademy/.pyenv/shims/python

--

--

Devesh Surve
Devesh Surve

Written by Devesh Surve

Grad student by day, lifelong ML/AI explorer by night. I dive deep, then share easy-to-understand, step-by-step guides to demystify the complex.

No responses yet