Post

Manage multiple Python versions with pyenv

Manage multiple Python versions with pyenv

At the time of this writing (2026), the latest release of Python is already at version 3.14, with pre-release of version 3.15 planned within the year. Python version 3.10 end of life is also slated within this year. Development is rapid, which is expected of this language with such an active and large community behind it. However, tools depending on Python are not necessarily updated to keep up with this schedule. And because if something works, why fix it, some of these tools may not be updated at all.

Hence, it might be necessary to keep multiple versions of Python in one machine. To make switching between versions easier, there’s a tool called pyenv. Unlike similar tools, pyenv does not itself depend on Python and is built purely from shell scripts. Essentially, because it uses shell scripts, it runs in Unix systems. This means that for Windows, Windows Subsystem for Linux (WSL) is required.

Installation

More detailed installation guide can be found in the pyenv Github page.

Here are the steps for MacOS:

Update Homebrew and install from there

1
2
brew update
brew install pyenv

Append the following to the shell configuration file to add pyenv to the startup commands. To know which shell the terminal is using, run echo $SHELL, e.g. for zsh

1
2
3
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrc

Additionally, the following might be needed to be added into .profile (if prompted)

Open .profile in an editor (e.g. vim), and add the following lines

1
2
3
4
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"

Run pyenv

Try checking if pyenv has been successfully installed and available from the terminal. If not, refresh the terminal first e.g. run zsh command.

Run

1
pyenv

To check the available versions of Python in the machine run

1
pyenv versions

system indicates the default Python available in the machine.

Install Python version

To install other Python versions, use pyenv install

Run help

1
pyenv install --help

List all available versions to download

1
pyenv install --list

Install a version e.g. version 3.10.7

1
pyenv install 3.10.7

Check if the are now new versions of Python installed in the machine

1
pyenv versions

Example output

1
2
* system (set by /Users/user/.pyenv/version)
  3.10.7

Use a Python version

To switch to the newly installed version, run either

1
pyenv shell 3.10.7

which enables usage of the version in the current terminal only, or to make the version available in a new terminal, run

1
python global 3.10.7

To switch back to the Python version originally installed in the machine, revert to the system installation

1
pyenv global system

Further resources

This post is licensed under CC BY 4.0 by the author.