pyenv: Python Version Manager
pyenv is a command-line tool for installing, managing, and switching between multiple Python interpreter versions on macOS and Linux. It intercepts Python commands through shell shims, routing them to whichever interpreter version is active for the current directory, user, or system.
When to use pyenv
pyenv fits workflows where Python version management should remain separate from package management. It pairs with pip, venv, or any other packaging tool without imposing opinions on how dependencies are managed. If you want a single tool that also handles dependencies and virtual environments, uv covers version management alongside those workflows.
Installation
Install with Homebrew:
brew install pyenvOr use the automatic installer:
curl https://pyenv.run | bashAfter installation, add pyenv to your shell startup file (.bashrc, .zshrc, or config.fish):
eval "$(pyenv init -)"Key Commands
Installing Python versions
pyenv compiles Python from source, which requires build dependencies but allows installing any CPython release, PyPy, or Anaconda/Miniconda distribution.
# List all available versions
pyenv install --list
# Install a specific version
pyenv install 3.12.4
# Uninstall a version
pyenv uninstall 3.12.4Switching versions
pyenv supports three scopes for version selection, each overriding the one below it:
# Set the version for the current shell session
pyenv shell 3.12.4
# Set the version for the current directory (writes a .python-version file)
pyenv local 3.12.4
# Set the default version for your user account
pyenv global 3.12.4The .python-version file that pyenv local creates is also recognized by uv, making migration straightforward.
Inspecting the current state
# Show the active Python version and how it was selected
pyenv version
# List all installed versions
pyenv versionsHow shims work
pyenv inserts a directory of lightweight wrapper scripts (shims) at the front of your PATH. When you run python, the shim checks pyenv’s configuration to determine which interpreter to forward the call to. This happens transparently; tools and editors that call python get the version pyenv selected without any changes on their end.
Limitations
- macOS and Linux only. Windows requires the separately maintained pyenv-win.
- Compiles from source. Installing a Python version requires C build tools and can take several minutes. Missing system libraries cause cryptic build failures.
- Version management only. pyenv does not handle virtual environments or dependencies. Use pyenv-virtualenv or a separate tool for environment management.
Related Handbook Pages
- How do pyenv and uv compare for Python interpreter management?
- How to switch from pyenv to uv for managing Python versions
- What is a .python-version file?
- pyenv-virtualenv reference
Learn More
Also Mentioned In
- uv: A Complete Guide to Python's Fastest Package Manager
- Hynek Schlawack's uv Workflow Guide
- Production Experiences with uv
- How do pyenv and uv compare for Python interpreter management?
- How do uv and Poetry compare?
- pyenv-virtualenv: Python Virtual Environment Plugin
- Should I use Homebrew to install Python?
- uv: Python Package and Project Manager
- venv: Python Built-in Virtual Environment Module
- virtualenv: Python Virtual Environment Tool
- What is a .python-version file?
- Which Python package manager should I use?
- Why You Should Try uv if You Use Python
Get Python tooling updates
Subscribe to the newsletter