Python Environments

Setting up specific python version

pyenv

Install prerequisites (so that we can build Python later)

Use pyenv-installer to get pyenv

Follow instructions at end of install to add to load path

Check it’s all working with:

$ pyenv doctor

Great article from Real Python on pyenv which explains a lot about how to use pyenv

Typical workflow

# Make sure I have an up to date list of python versions
pyenv update

# find options for exact python version to install
pyenv install --list | grep 3.8

# install exact python version I want
pyenv install 3.8.7

# create virtualenv
pyenv virtualenv 3.8.7 environment_name

# activate
pyenv activate environment_name
pyenv deactivate
# activate in this directory and sub-directories
pyenv local environment_name

Then I can point PyCharm at my environment by selecting existing virtualenv with path:

# while <environment_name> is active
pyenv which python 

See also