- Install pyenv
brew install pyenvThis uses Homebrew.
- Load pyenv in every new terminal
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrcThen close this terminal and open a new one so the change takes effect.
- See which versions you can install
pyenv install --listThe list is long. Plain numbers like 3.12.7 are the standard Python releases.
- Install a version
pyenv install 3.12.7pyenv builds Python from source, so this can take a few minutes.
- Use it everywhere by default
pyenv global 3.12.7 - Use it in one project only
pyenv local 3.12.7Run this inside the project folder. It writes a .python-version file there, and pyenv switches to that version whenever you are in the folder.
- List the versions you have
pyenv versionsThe one with a star is the version in use right now.
Check it worked
- Check which Python runs
python --version - Check the Python comes from pyenv
pyenv which python
Undo it
- Go back to the system Python
pyenv global system - Remove a version you installed
pyenv uninstall -f 3.12.7
- Install the build tools Python needsNeeds sudo
sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libffi-dev liblzma-dev tk-devThis is for Ubuntu and Debian. pyenv builds Python from source and fails without these. Other systems need the same libraries from their own package manager.
- Install pyenv
curl -fsSL https://pyenv.run | bashThis downloads the official pyenv installer and puts pyenv in ~/.pyenv.
- Load pyenv in every new terminal
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc echo 'eval "$(pyenv init - bash)"' >> ~/.bashrcThen close this terminal and open a new one so the change takes effect.
- See which versions you can install
pyenv install --listThe list is long. Plain numbers like 3.12.7 are the standard Python releases.
- Install a version
pyenv install 3.12.7pyenv builds Python from source, so this can take a few minutes.
- Use it everywhere by default
pyenv global 3.12.7 - Use it in one project only
pyenv local 3.12.7Run this inside the project folder. It writes a .python-version file there, and pyenv switches to that version whenever you are in the folder.
- List the versions you have
pyenv versionsThe one with a star is the version in use right now.
Check it worked
- Check which Python runs
python --version - Check the Python comes from pyenv
pyenv which python
Undo it
- Go back to the system Python
pyenv global system - Remove a version you installed
pyenv uninstall -f 3.12.7
- Install pyenv-win
winget install -e --id pyenv-win.pyenv-winpyenv itself doesn't run on Windows, so this is pyenv-win, a version made for Windows. You can also use the PowerShell installer from the pyenv-win README. Open a new terminal afterwards.
- See which versions you can install
pyenv install --list - Install a version
pyenv install 3.12.7 - Use it everywhere by default
pyenv global 3.12.7 - Use it in one project only
pyenv local 3.12.7Run this inside the project folder. It writes a .python-version file there, and pyenv switches to that version whenever you are in the folder.
- List the versions you have
pyenv versionsPrefer not to install anything? Windows already has the py launcher, which picks a version you installed from python.org, for example py -3.12.
Check it worked
- Check which Python runs
python --version - Check the Python comes from pyenv
pyenv which python
Undo it
- Remove a version you installed
pyenv uninstall 3.12.7pyenv-win has no system option, so removing the version is how you stop using it.