Pyenv: A Guide to Creating and Managing Different Python Versions

PrimerPy
2 min readJan 30, 2023

Python is a versatile programming language and its applications are spread across a wide range of domains. As a result, multiple versions of the language are used in different projects, and developers may need to switch between them frequently. This is where Pyenv comes into the picture.

Pyenv is a simple Python version manager that helps you manage multiple versions of Python on a single machine. In this post, we’ll be discussing how you can use Pyenv to create and manage different versions of Python.

Installing Pyenv

Pyenv can be installed using the following command:

curl https://pyenv.run | bash

Once installed, you need to add the following lines to your shell profile file (e.g. ~/.bashrc or ~/.zshrc) to make sure Pyenv is available in your shell:

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"

Reload the shell profile to enable Pyenv:

source ~/.bashrc (or ~/.zshrc)

Installing Python Versions

To install a new Python version, use the following command:

pyenv install <version>

For example, to install Python 3.9.1, run:

pyenv install 3.9.1

You can list all the available versions of Python using the following command:

pyenv versions

Setting the Global Python Version

To set the global Python version, use the following command:

pyenv global <version>

For example, to set Python 3.9.1 as the global version, run:

pyenv global 3.9.1

Setting the Local Python Version

To set the local Python version for a specific project, use the following command:

pyenv local <version>

For example, to set Python 3.8.7 as the local version for a project, run:

pyenv local 3.8.7

Uninstalling Python Versions

To uninstall a Python version, use the following command:

pyenv uninstall <version>

For example, to uninstall Python 3.9.1, run:

pyenv uninstall 3.9.1

In conclusion, Pyenv is a powerful tool for managing multiple Python versions on a single machine. With Pyenv, you can easily switch between different versions, set the global and local versions, and uninstall versions that are no longer needed. We hope this guide helps you make the most of Pyenv and streamlines your Python development workflow.

--

--

PrimerPy

www.primerpy.com | A Primer on Python. I'm a veteran Data and Web developer based out of NYC and DC area. I blog mainly on Python and other tech related topics.