Here is the pyenv cheat sheet of all the basic commands list.

What is pyenv

pyenv is Python version management tool, it lets you easily switch between multiple versions of Python.

What it does

  • Lets you change the global Python version on a per-user basis.

  • Provides support for per-project Python versions.

  • Allows you to override the Python version with an environment variable.

List available python versions to install

This will list all the available version of python

1
pyenv install --list

You can filter it using grep. Here we are filtering list by python version:

1
pyenv install --list | grep " 3\.11"

Installing Python Version

1
pyenv install <version>

add -v flag to see install progress output

List Installed Python Versions

1
pyenv versions

Astrick (*) indicate current active version.

See List Of All pyenv Commands

1
pyenv commands

Activating Python Version

global

  • Sets the given version as global python version.

  • It overrides system’s default python version.

1
pyenv global <version>

local

  • Use it to set directory / project specific python version.

  • It can override python version set by global

1
pyenv local <version>

shell

  • Sets shell specific python version.

  • The python version stays active until shell has been closed or by using --unset flag.

  • It can override python version set by local and global

1
pyenv shell <version>

Virtual Environments

Create Virtual Environments

1
pyenv virtualenv <version> <env_name>

Set virtual environment as default for dir/project

1
pyenv local <env_name>

Activate Virtual Environment

1
pyenv activate <env_name>

Deactivate Virtual Environment

1
pyenv deactivate