Mainly a summary from Managing Multiple Python Versions With pyenv
In a Debian based systems, as root:
apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
In your home, as user:
$ curl https://pyenv.run | bash
Add to the end of your ~/.bashrc
:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Reload your shell (or restart your terminal):
exec "$SHELL"
To check the available versions, run:
pyenv install --list
If you’ve been using pyenv for a while and don’t see the version you’re looking for, you may need to run
pyenv update
.
To install the desidered VERSION:
pyenv install -v VERSION
This will take a while because pyenv is building Python from source.
To check that the version of Python is working properly, you can run the built-in test suite
python -m test
Check the installed versions:
pyenv versions
Select which VERSION to use globally:
pyenv global VERSION
Select which VERSION to use locally (to a project):
pyenv local VERSION
Select which VERSION to use in the current shell:
pyenv shell VERSION
You can see a complete list of all available commands with:
pyenv commands
If you wanted to see more information on a COMMAND you could run:
pyenv COMMAND --help
Each version that you have installed is located in your pyenv root directory (
ls ~/.pyenv/versions/
)
You can remove (rm -fr
) the directory of a particular VERSION or run:
pyenv uninstall VERSION
If you need a Python version with --enable-shared
(cocotb), which Pyenv doesn’t use by default:
$ PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install -v VERSION