The pyenv package is a very useful tool for managing multiple versions of Python, without too much hassle. It also comes with various plugins for streamlining the development experience, including pyenv-virtualenv, which provides features for managing virtual environments and conda environments.
Unfortunately, pyenv is not supported on Windows. However, we recommend using the pyenv-win fork for Windows users.
Mac OS X
brew install openssl readline sqlite3 xz zlib
Ubuntu/Debian/Mint
sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \ libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
Alpine
apk add --no-cache git bash build-base libffi-dev openssl-dev bzip2-dev zlib-dev readline-dev sqlite-dev
The fastest way to install pyenv and some of popular plugins is to use the pyenv-installer:
curl https://pyenv.run | bash
Next up, restart your shell so the path changes take effect:
exec $SHELL
Updating pyenv is as simple as:
pyenv update
The pyenv executable is installed in $PYENV_ROOT, which defaults to ~/.pyenv. To uninstall it, just simply remove it:
rm -fr ~/.pyenv
Then clean up your .bashrc file, by removing the following lines from it:
export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv virtualenv-init -)"
In this article we've learned how simple and easy it is to use pyenv and its related plugins for managing multiple versions of Python and virtual environments from a single machine.
This article was originally published here.
The above is the detailed content of Managing Python Versions and Virtual Environments using pyenv. For more information, please follow other related articles on the PHP Chinese website!