In many ways this is a note to my future self. Sometime in the future I will need to setup a MacBook Pro including installing Python. Instead of fumbling around and failing to correctly install Python, I’ll refer to this article on how to do it the correct way.

As of this writing, MacOS used to come bundled with a deprecated version of Python. You should install and use a supported version of Python. However, certain versions of many Python based tools only work with certain versions of Python (cough cough Ansible cough cough). Let’s walk through the process of installing multiple Python environments on your MacOS machine.

Step 1 - Install Homebrew

Homebrew is a package manager that makes it easy to install applications (and their dependencies).

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2 - Install Pyenv

Pyenv let’s you install and easily switch between multiple versions of Python.

brew install pyenv

Step 3 - Install Python

Python is a programming language. We’ll install and make Python 3.10.6 the default.

pyenv install 3.10.6
pyenv global 3.10.6

Execute pyenv versions to see a list of all installed versions of Python

  system
  2.7.8
* 3.10.6 (set by /Users/eh/.pyenv/version)

If you need to change the version of Python temporarily (for a single terminal session):

pyenv local 2.7.8

It will revert to the global version starting with the next terminal session.

🧇