Introcuction

Pyenv is a similar tool to rbenv, where you can easily install and use mulitple versions of python. This allows you to test across multiple versions of python as well as pin an app to a specific release.

Software Versions Used

  • Centos - 8.2.2004
  • Pyenv - 1.2.21

Pre-requisites

Install the dependencies required to use pyenv.

cmd

sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y zlib zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel
    

Installation

Use the installed script to install pyenv.

cmd

curl https://pyenv.run | bash
    

Update your shell environment, I am using zsh.

file

# ~/.zshrc

# PYENV
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"

# PYENV Auto-completions. This should be towards the end of the file.
eval "$(pyenv init -)"
    

Restart your shell environment.

cmd

exec "$SHELL"
    

Verify the version of pyenv installed.

cmd

pyenv --version

# output
pyenv 1.2.21
    

Usage

Install a version of python.

cmd

# Python 3
pyenv install 3.8.6

# Python 2
pyenv install 2.7.16
    

Install a version of python.

cmd

# Python 3
pyenv install 3.8.6

# Python 2
pyenv install 2.7.16
    

Use a version of python.

cmd

# Application specific python version(s).
pyenv local 3.8.6 2.7.16

# Systemwide python version(s)
pyenv global 3.8.1 2.7.18
    

Summary

Welcome to the end. If you followed along you will have pyenv installed and configured for use on Centos 8.

Tags

python pyenv centos linux