pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.
Installation
In this topic, we will install pyenv on macOS.
Install pyenv
pyenv builds Python from source, which means you’ll need build dependencies to actually use pyenv. On macOS, you can install these dependencies with Homebrew:
brew install openssl readline sqlite3 xz zlib
After you’ve installed the build dependencies, you’re ready to install pyenv itself. I recommend using the pyenv-installer project:
curl https://pyenv.run | bash
This will install pyenv along with a few plugins that are useful:
- pyenv: The actual pyenv application
- pyenv-virtualenv: Plugin for pyenv and virtual environments
- pyenv-update: Plugin for updating pyenv
- pyenv-doctor: Plugin to verify that pyenv and build dependencies are installed
- pyenv-which-ext: Plugin to automatically lookup system commands
Then add the following to your ~/.zshrc
:
# Python Version Manager
export PATH="$HOME/.pyenv/bin:$PATH"
alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
Usage
List available Python versions
pyenv install --list
Install Python
pyenv install 3.11.0
Set Python version globally
pyenv global 3.11.0
Set Python version locally
pyenv local 3.11.0
Uninstall Python
pyenv uninstall 3.11.0
List installed Python versions
pyenv versions
Update pyenv
brew upgrade pyenv
PIP
Install PIP
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Top comments (0)