My Python Setup

09 Nov 2020

I work on macOS Catalina but I imagine that this setup (mostly) works for earlier macOS versions.

In order to not mess up my system-installed Python distribution, I use pyenv to manage different Python versions. This is particularly helpful for me because I am working on multiple projects that usually use different Python interpreters at any given moment.

To install pyenv with Homebrew:

$  brew update
$  brew install pyenv

Once pyenv is installed, follow step 3 here.

To isolate projects from one another, I use poetry instead of managing my own virtualenv. Since poetry can detect whether I’m currently in an activated virtualenv, it will use that existing one or create a new one.

To install poetry:

$  curl -sSL | python -

When I use poetry, I either initialize a new project with poetry new or create a new project by hand with poetry init:

$  mkdir new-proj && cd new-proj
$  poetry init

All of my .virtualenvs also exist outside of my project folders and in my home directory ($HOME/.virtualenvs).

$  poetry config virtualenvs.path $HOME/.virtualenvs

The default .virtualenv path of poetry is {cache-dir}/virtualenvs which can be a bit harder to find depending on your OS. If you’re like me and you use PyCharm, finding that virtualenv so you can configure your Project Interpreter can be a pain.

I’ve found that this setup requires the least effort and works just as well when I need to work with scientific packages.