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:
- Open your shell configuration file (
.bashrc,.zshrc, etc.) - Remove or comment out lines like:
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"- 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 # macOS3. Transition to uv’s Python Management
Instead of pyenv commands, you’ll now use uv’s equivalents:
- Replace
pyenv install 3.12withuv python install 3.12 - Replace
pyenv versionswithuv python list - Replace
pyenv local 3.12withuv python pin 3.12
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.txtCreate the new environment and reinstall from that list:
uv add -r requirements.txtThis 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-versionfile is still supported for version pinning
Learn More
- uv: A Complete Guide covers what uv does, how fast it is, the core workflows, and recent releases.
- What is a .python-version file?
- How to add Python to your system path with uv
- How do pyenv and uv compare for Python interpreter management?