Manage multiple Python versions with ease.
Pyenv is a tool that lets you manage and install multiple Python versions (à la nvm). It makes getting the latest versions on Linux much easier.
However, its README is pretty hard to skim, especially when encountering pyenv for the first time. Here's my attempt at providing some more concise documentation.
How to install pyenv on Debian-based systems
Adapted from the official installation instructions.
If you run into problems, review the troubleshooting section of the pyenv wiki.
Pyenv needs certain dependencies in order to build Python for your OS. Install them with these commands:
sudo apt update sudo apt install \ build-essential \ curl \ git \ libbz2-dev \ libffi-dev \ liblzma-dev \ libncursesw5-dev \ libreadline-dev \ libsqlite3-dev \ libssl-dev \ libxml2-dev \ libxmlsec1-dev \ llvm \ make \ tk-dev \ wget \ xz-utils \ zlib1g-dev
Clone the pyenv repository to a folder in your home directory:
git clone https://github.com/pyenv/pyenv.git $HOME/.pyenv
Add the following lines to your
.bashrcfile (or the equivalent for your shell):
# Pyenv setup export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv init -)"
Restart your terminal session.
Install the version of Python you want to use:
pyenv install 3.10.0
Set that version of Python as your current version:
pyenv global 3.10.0
Now you should be good to go! When you check your Python version, you should see:
$ python --version Python 3.10.0