$linuxjunkies
>

pyenv(1)

pyenv manages multiple Python versions on a single system, allowing you to switch between them per-project or globally.

UbuntuDebianFedoraArch

Synopsis

pyenv <command> [<args>]

Description

pyenv is a version manager for Python that lets you install and switch between multiple Python versions without system-wide installation conflicts. It works by inserting a shim directory at the front of your PATH, intercepting Python calls and redirecting them to the appropriate version.

Unlike system package managers, pyenv installs Python versions into your home directory (~/.pyenv/versions), giving you complete control over versions per-project, per-shell session, or globally. It integrates with .python-version files to automatically switch versions when entering a directory.

Common options

FlagWhat it does
versionslist all installed Python versions; asterisk marks the currently active version
installdownload and compile a Python version; use --list to see available versions
uninstallremove an installed Python version from ~/.pyenv/versions
globalset the global default Python version in ~/.pyenv/version
localset the Python version for the current directory via .python-version file
shellset the Python version for the current shell session only
versionshow the currently active Python version and how it was set
whichdisplay the full path to the executable for the active Python version
rehashrefresh shim directory when new Python versions or executables are added
-v / --versiondisplay pyenv version number

Examples

see available Python 3.12.x versions before installation

pyenv install --list | grep '3.12'

download, compile, and install Python 3.12.1 into ~/.pyenv/versions

pyenv install 3.12.1

list all installed Python versions; the active one is marked with an asterisk

pyenv versions

set Python 3.12.1 as the default version system-wide

pyenv global 3.12.1

set Python 3.11.0 for the current directory; creates .python-version file

pyenv local 3.11.0 && cat .python-version

use Python 3.10.5 for only the current shell session

pyenv shell 3.10.5 && python --version

show the full path to the currently active python executable

pyenv which python

remove Python 3.9.0 from the system

pyenv uninstall 3.9.0

Related commands