Skip to content

How to switch from pyenv to uv for managing Python versions

This guide shows how to transition from using pyenv to uv for managing Python versions. While pyenv has been a reliable tool for many years, uv offers faster performance and more integrated workflows.

Steps to Switch

1. Remove pyenv Integration From Shell

Remove pyenv initialization from your shell configuration files:

  1. Open your shell configuration file (.bashrc, .zshrc, etc.)
  2. Remove or comment out lines like:
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
  1. Reload your shell configuration:
source ~/.bashrc  # or .zshrc, etc.

2. Clean Up pyenv Installation

Remove pyenv from your system:

# Remove pyenv versions and configuration
rm -rf ~/.pyenv

# Or if installed via package manager
brew uninstall pyenv  # macOS

3. Transition to uv’s Python Management

Instead of pyenv commands, you’ll now use uv’s equivalents:

  • Replace pyenv install 3.12 with uv python install 3.12
  • Replace pyenv versions with uv python list
  • Replace pyenv local 3.12 with uv python pin 3.12
Unlike pyenv, uv will automatically download and install required Python versions when they’re needed. You don’t need to explicitly install versions unless you want them available offline.

4. Move Each Environment’s Packages to uv

pyenv-managed environments stop working once pyenv is gone, so recreate each one with uv. Export the installed packages first, or you’ll lose them.

Capture the current packages while the old environment still exists:

# Activate the old pyenv environment, then:
pip freeze > requirements.txt

Create the new environment and reinstall from that list:

uv add -r requirements.txt

This records the packages as project dependencies and writes a lockfile. uv creates the .venv/ automatically.

pip freeze pins every package, including transitive dependencies, so uv add -r requirements.txt adds those sub-dependencies as top-level entries. For a cleaner pyproject.toml, run uv add with only the packages you import directly (uv add requests flask) and let uv resolve the rest.

Adjusting Your Workflow

Key differences to note:

  • Virtual environments are typically managed automatically by uv when running commands
  • Python versions are downloaded on-demand rather than requiring explicit installation
  • The .python-version file is still supported for version pinning

Learn More

Last updated on