Install several Python versions side by side, switch between them with one command and pin a version for each project, on Mac, Linux and Windows.
7 min read·Last updated
What is pyenv?
Short answer: pyenv is a tool that installs several Python versions on the same computer and lets you switch between them with one command. Each project can use its own version, and the Python that came with your system stays untouched.
bash
pyenv install 3.15.2 # install a versionpyenv global 3.15.2 # default for your usercd old-app && pyenv local 3.14.10 # this folder uses 3.14python --version # Python 3.14.10
pyenv works on macOS and Linux. On Windows you use pyenv-win, a separate project with the same commands. At the time of writing, the latest releases are pyenv 2.8.14, pyenv-win 3.1.1 and Python 3.15.2.
pyenv install downloads a version, pyenv global makes it your default and pyenv local pins a different one for a single project.
pyenv commands at a glance
What you want
Command
See which versions you can install
pyenv install --list
Install a version
pyenv install 3.15.2
See the versions you have
pyenv versions
Set the default for your user
pyenv global 3.15.2
Use a version in one project folder
pyenv local 3.14.10
Use a version only in this terminal
pyenv shell 3.14.10
See which version is active and why
pyenv version
See the path of the active Python
pyenv which python
Remove a version
pyenv uninstall 3.14.10
What is pyenv used for?
Different projects, different versions. An old app may need Python 3.12 while a new one uses 3.15. pyenv switches automatically when you enter each folder.
Try a new version safely. Install the latest Python next to the one you use, test your code and go back with one command.
No sudo and no system changes. Every version lives in ~/.pyenv/versions, inside your user folder. macOS and Linux tools that depend on the system Python keep working.
The same version for the whole team. Commit the .python-version file and everyone with pyenv gets the same Python in that project.
pyenv chooses the version in this order: the PYENV_VERSION variable (set by pyenv shell), a .python-version file in the current folder or a parent folder (set by pyenv local), and finally the global version.
Career · AI Engineering
Your Python setup is ready, now build with AI
From zero to junior AI Engineer: Python, data, AI agents and RAG with mentors and real projects.
If you have ~/.profile or ~/.bash_profile, add the same three lines there too, changing the file name. With zsh, use ~/.zshrc and pyenv init - zsh, as on Mac.
4. Restart the shell:exec "$SHELL", then check it with pyenv --version.
Install pyenv on Windows with pyenv-win
pyenv itself doesn't run on Windows. Install pyenv-win from PowerShell:
Close and reopen PowerShell, then run pyenv --version. The commands are the same as on Mac and Linux: pyenv install, pyenv global and pyenv local. Run pyenv update first so pyenv-win knows the newest Python versions.
If you work in WSL (Ubuntu on Windows), follow the Linux steps inside WSL instead.
Install and switch Python versions
bash
pyenv install --list | grep " 3.15" # versions you can installpyenv install 3.15.2pyenv install 3.14.10pyenv versions# system# 3.14.10# * 3.15.2 (set by /home/ana/.pyenv/version)
Set the default version for your user, and a different one for a project:
bash
pyenv global 3.15.2cd old-apppyenv local 3.14.10 # creates old-app/.python-versionpython --version # Python 3.14.10
When you leave the folder, the global version is back. To go back to the Python that came with your system, run pyenv global system.
pyenv vs venv: use both
They solve different problems:
pyenv
venv
What it manages
Python versions (3.14, 3.15...)
The packages of one project
Where it lives
~/.pyenv/versions
A .venv folder in the project
Typical command
pyenv local 3.15.2
python -m venv .venv
The usual setup is pyenv to choose the version and venv for the packages:
bash
cd my-apppyenv local 3.15.2python -m venv .venvsource .venv/bin/activatepip install requests
The pyenv-virtualenv plugin can create environments with pyenv virtualenv 3.15.2 my-app, but plain venv is enough for most projects.
Update pyenv
Installed with Homebrew: brew update && brew upgrade pyenv
Installed with pyenv.run: pyenv update
Installed with git: git -C ~/.pyenv pull
pyenv-win: run the PowerShell installer again, or pyenv update to refresh the list of versions
Update pyenv when pyenv install --list doesn't show a Python version that was just released.
Use AI to set up pyenv
An assistant like ChatGPT, Claude or GitHub Copilot can adapt the setup to your system and read an install error with you. These three prompts are ready to copy.
1. Set up pyenv for your system
I use [macOS on Apple Silicon / Ubuntu 24.04 / Windows 11] with [zsh / bash / PowerShell].Give me the exact steps to install pyenv, set it up in my shelland install Python [version]. Explain what each step does.
2. Fix a failed install
pyenv install [version] failed on [your system] with this output:[paste the last 30 lines]Explain which dependency is missing and give me the command to fix it.
3. Set up a project
My project needs Python [version] and these packages: [list them].Show me how to set it up with pyenv local and venv so my team gets the same setup.
Read each command before you run it, especially the ones that use sudo or change your shell files.
Learn with a mentor
From managing Python versions to AI applications
In the 4Geeks AI Engineering career program you start with no experience and finish with AI agents and RAG systems in your portfolio.
Install pyenv on Mac, Linux and Windows, every command to install and switch Python versions, shell setup, pyenv with venv, common errors and prompts for ChatGPT, Claude or Copilot. Free, in PDF.
pyenv cheat sheet
2 pages · PDF · 4Geeks
The install steps for Mac, Linux and Windows
Every pyenv command in one table
Common errors and prompts to solve them with AI
Get it free
Your PDF right away
Frequently asked questions about pyenv
Want to go from setting up Python to building AI applications, with real projects and mentors?