About Using Multiple Python Versions

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

$ curl https://pyenv.run | bash

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

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

List available Python versions for installation with:

$ pyenv install --list

To install Python 3.10.2 you would:

$ 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:

$ ~/.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