Python Setup

Installing and configuring Python.

Michael McCarthy


January 24, 2023


Python is an open source programming language that is the “second best language for everything.” It’s worth setting up in case you need it, but for data science R is almost always simpler and better.

Installing pyenv

pyenv is an open source Python installation manager for installing, removing, and switching between multiple Python versions.

  1. Install pyenv from the Terminal with Homebrew:

    brew install pyenv
  2. Set up your shell environment for pyenv.

  3. Install Python build dependencies with Homebrew:

    brew install openssl readline sqlite3 xz zlib tcl-tk

Installing Python

Install the latest major version of Python 3 with shared library support1 from the Terminal with pyenv:

env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3:latest

Installing pipenv or poetry

pipenv is an open-source dependency manager for Python projects.

Install pipenv from the Terminal with Homebrew:

brew install pipenv

poetry is an alternative open-source dependency manager for Python projects. I’m currently experimenting between poetry and pipenv to decide which I prefer.

Install poetry from the Terminal with:

curl -sSL | python3 -

Installing pipx

pipx is open-source package manager for installing and running command line applications written in Python in separate environments from your Python libraries. It’s like Homebrew, but for Python applications.

Install pipx from the Terminal with:

brew install pipx
pipx ensurepath

Calling Python from R

Use the reticulate R package to interface R and Python in the same project. reticulate has support for projects using pipenv or poetry.


  1. Shared library support is needed to use Python versions with reticulate.↩︎