Install pyenv on MacOS


I’m a big fan of pyenv, a slick way to manage Python on UNIX or Linux systems. It can be installed on MacOS systems, but it’s not quite as straight-forward.

Preparation

  1. Install homebrew
  2. Install prerequisite packages:
    brew install readline xz
  3. Download and install the latest CommandLineTools from the Apple Developer site.

Install

  1. Install pyenv with brew:
    homebrew install pyenv
  2. Install a Python version:
    CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install -v 3.7.1
  3. Update pip:
    pip install --upgrade pip
  4. In step #2, substitute 3.7.1 for whatever version of Python you wish to install with pyenv.