About Using Multiple Python Versions

First of all, install pyenv using https://github.com/pyenv/pyenv-installer:

1
$ curl https://pyenv.run | bash

Append these lines to ~/.zshrc or ~/.bash_profile depending on your shell:

1
2
3
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"

List available Python versions for installation with:

1
$ pyenv install --list

To install Python 3.10.2 you would:

1
$ pyenv install 3.10.2

It will be installed to ~/.pyenv/versions/.

To create a new virtual environment with Python 3.10.2 you would run this in a directory where you want your venv directory:

1
$ ~/.pyenv/versions/3.10.2/bin/python -m venv venv

Analogously you can set up other Python versions.

Tips and Tricks Dev Ops Development Python 3 pyenv