This will be a micro-post talking about managing multiple python versions on your machine, using a tool called Pyenv.
Depending on your operating system, it may be quite a hassle uninstalling and installing different python versions. And in some cases, you may want to run multiple projects that use different python versions at the same time. With Pyenv it is no big deal.
The installation process is very straightforward:
curl https://pyenv.run | bash
This will print out the following three lines that you should add to your ~/.bashrc
or ~/.zshrc
file:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
After restarting your shell, you can run Pyenv:
pyenv --help
To see which versions are installed, run:
➜ pyenv versions
system
3.7.5
* 3.8.0 (set by /home/stefan/.pyenv/version)
You can install new python versions using:
pyenv install 3.8.0
And you can set the global python version with:
pyenv global 3.8.0
To remove the installation, run:
rm -rf $(pyenv root)
And clean up the lines that you inserted in ~/.bashrc
or ~/.zshrc
, in Installing Pyenv.