use several versions of Python with pyenv
Pyenv is a tool available on Linux and macOS to easily install several versions of Python in the same system.
Installation of dependancies:
*Ubuntu/Debian:
sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl git llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
*CentOS/Fedora/RHEL:
dnf install make gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel xz-devel
*other: please, visit the official documentation.
Installation:
curl https://pyenv.run | bash
Make sure that these 3 lines are in the .bashrc file. If not, add them :
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
eval "$(pyenv init -)"
Restart the shell :
exec $SHELL
Then, update pyenv to get the list of available Python versions:
pyenv update
List of available Python versions:
pyenv install -l
Available versions:
2.1.3
2.2.3
2.3.7
...
3.9.0
3.9-dev
3.9.1
3.9.2
3.9.4
3.9.5
3.9.6
3.9.7
3.9.8
3.9.9
3.9.10
3.10.0
3.10-dev
3.10.1
3.10.2
3.11.0a4
3.11-dev
...
stackless-2.7.12
stackless-2.7.14
stackless-2.7.16
stackless-3.2.2
stackless-3.2.5
stackless-3.3.5
stackless-3.3.7
stackless-3.4-dev
stackless-3.4.2
stackless-3.4.7
stackless-3.5.4
stackless-3.7.5
It is also possible to install versions of :
Anaconda
ActivePython
GraalPython
IronPython
Jython
MicroPython
MiniConda
PyPy
Pyston
stackless
Python 3.10.2 installation :
pyenv install 3.10.2
Make Python 3.10.2 the default version of the current shell :
pyenv shell 3.10.2
Make Python 3.10.2 the default version of the current user :
pyenv global 3.10.2
Get the list of commands:
pyenv -h
Usage: pyenv []
Some useful pyenv commands are:
activate Activate virtual environment
commands List all available pyenv commands
deactivate Deactivate virtual environment
doctor Verify pyenv installation and development tools to build pythons.
exec Run an executable with the selected Python version
global Set or show the global Python version(s)
help Display help for a command
hooks List hook scripts for a given pyenv command
init Configure the shell environment for pyenv
install Install a Python version using python-build
local Set or show the local application-specific Python version(s)
prefix Display prefix for a Python version
rehash Rehash pyenv shims (run this after installing executables)
root Display the root directory where versions and shims are kept
shell Set or show the shell-specific Python version
shims List existing pyenv shims
uninstall Uninstall a specific Python version
--version Display the version of pyenv
version Show the current Python version(s) and its origin
version-file Detect the file that sets the current pyenv version
version-name Show the current Python version
version-origin Explain how the current Python version is set
versions List all Python versions available to pyenv
virtualenv Create a Python virtualenv using the pyenv-virtualenv plugin
virtualenv-delete Uninstall a specific Python virtualenv
virtualenv-init Configure the shell environment for pyenv-virtualenv
virtualenv-prefix Display real_prefix for a Python virtualenv version
virtualenvs List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
whence List all Python versions that contain the given executable
which Display the full path to an executable
See `pyenv help ' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme