pyenv: install several Python versions and switch between them

Researched, not yet tested: compiled from the pyenv README and wiki (pyenv v2.8.15) as of 30 November 2026; we couldn't run the pyenv installer in our test environment. Check the commands against your setup.

pyenv installs several Python versions side by side and picks one per shell, per project or for your whole account. On a Mac, install it with Homebrew and add it to your shell:

brew install pyenv
pyenv init --install
exec "$SHELL"

On Linux, use the installer from the README: curl -fsSL https://pyenv.run | bash, then ~/.pyenv/bin/pyenv init --install. Then install a Python version and select it:

pyenv install 3.13
pyenv global 3.13
python --version

We couldn’t run the pyenv installer in our test environment, so this page is researched from the pyenv README and its wiki (pyenv v2.8.15, 30 November 2026). pyenv init --install is a recent addition. If your pyenv doesn’t have it, use the manual lines in the shell setup section below.

Install the build dependencies first

The README notes that most Python versions pyenv installs are built from source, so pyenv install needs a compiler and libraries. A missing library is a common reason for a failed install. The wiki’s suggested build environment lists:

On a Mac (after xcode-select --install, see the Command Line Tools guide):

brew install openssl@3 openssl readline sqlite3 xz tcl-tk@8 libb2 zstd zlib pkgconfig

On Ubuntu or Debian:

sudo apt update; sudo apt install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl git \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev libzstd-dev

If a build still fails, the wiki’s Common build problems page lists fixes by error message.

Set up your shell by hand

If you’d rather edit your shell file yourself, the README’s lines for zsh are:

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

For bash, the README puts the same three lines (with pyenv init - bash) in your login startup file. Restart the shell with exec "$SHELL" afterwards.

Choose a version: global, local or shell

Command Applies to Stored in
pyenv shell 3.12 This terminal only The PYENV_VERSION variable
pyenv local 3.12 This folder and its subfolders A .python-version file
pyenv global 3.13 Your account, everywhere else $(pyenv root)/version

pyenv checks them in that order: PYENV_VERSION first, then a .python-version file in the current folder or any parent, then the global setting. system as a version name means “whatever Python was on PATH before pyenv”. Commit .python-version to a project’s repository so everyone uses the same version.

Short versions resolve automatically. The README says pyenv install 3.13 picks the latest known 3.13 release, and other commands pick the latest installed one.

Other useful commands

Task Command
List versions you can install pyenv install -l
List installed versions pyenv versions
Show which version is active and why pyenv version
Show where a version is installed pyenv prefix 3.13
Remove a version pyenv uninstall 3.12.4
Make two versions available at once (for tox) pyenv global 3.12 3.13
See all commands pyenv commands

pyenv with virtual environments

pyenv chooses the interpreter. Each project should still have its own virtual environment for packages:

pyenv local 3.13
python -m venv .venv
source .venv/bin/activate

This also avoids the externally-managed-environment error. The separate pyenv-virtualenv plugin adds commands for creating and switching environments through pyenv, if you prefer that.

pyenv or uv for Python versions

uv can also install Python. Its docs show uv python install 3.12, using prebuilt builds from the python-build-standalone project, so nothing is compiled. By default uv only adds versioned commands such as python3.12. The --default option, marked experimental, also installs python and python3. pyenv suits you if you want shims that switch automatically by folder or builds compiled on your machine. uv suits you if you already use it for packages and want fast installs.

Fix common pyenv problems

  • python still runs the old version. The shims folder isn’t early enough on PATH. Check that the pyenv init line is in your shell file, run exec "$SHELL", then pyenv version to see which setting won.
  • pyenv: command not found after a Linux install. The installer put pyenv in ~/.pyenv/bin. Run ~/.pyenv/bin/pyenv init --install or add the manual lines above, then restart the shell.
  • The build fails with a missing module (_ssl, _sqlite3, readline). A library from the build dependencies list was missing when Python compiled. Install it, then run pyenv install again for that version.
  • brew doctor warns about “config” scripts. The README gives an alias that hides pyenv’s shims from Homebrew. You only need it if you build Homebrew formulae from source. See brew doctor warnings.

Uninstall pyenv

The README’s steps: remove every pyenv line from your shell startup files, then delete its folder, which deletes all Python versions pyenv installed:

rm -rf $(pyenv root)

If you installed it with Homebrew, also run brew uninstall pyenv. To only stop pyenv from switching versions, removing the pyenv init lines is enough.

FAQ

Is pyenv deprecated?

No. pyenv is still maintained: its latest release tag on 30 November 2026 was v2.8.15, with commits in the same week. Some people now use uv to install Python versions instead, but that's a choice of tool, not a deprecation.

What's the difference between pyenv and venv?

pyenv installs and switches Python interpreters (3.12, 3.13 and so on). venv creates an isolated folder of packages for one project using an interpreter you already have. They work together: pick the version with pyenv, then create a venv with that version's python -m venv .venv.

Which is better, pyenv or uv?

uv downloads prebuilt Python builds (uv python install 3.12), so it's faster and needs no compiler. pyenv builds most versions from source, which needs build dependencies but gives you a standard CPython build compiled on your machine. If you already use uv for packages, its Python management is usually enough.

Is pyenv available on Windows?

Not natively. The pyenv README says it doesn't officially support Windows and only works inside WSL, where it installs Linux builds. It recommends the separate pyenv-win project for native Windows Python versions.