TIL: Pythons 2 and 3 can coexist under pyenv

pyenv is a wonderful tool for managing multiple Python versions on your system. It uses shims to select a specific interpreter either globally, per-directory or per-shell.

I recently learned that you can actually select both a Python 2 and a Python 3 interpreter in a single context. For example:

pyenv shell 3.7.3 2.7.15

Will, in effect, select Python 3.7.3 as the "primary" python version in your shell, so that python and python3 will point to it. But it will also set python2 to point to Python 2.7.15.

For context, this came up because we use Python 3 internally for everything, but some tools (notably some gcloud SDK tools) still require Python 2. In almost-2020.

Show Comments