Installing and Managing Multiple Python Versions in Mac Using Pyenv

In this tutorial we will learn about installing and managing multiple python versions in Mac using Pyenv.

Introduction

Pyenv is simple python version management tool. It helps in installing multiple python versions and seamlessly switching between these versions.

Installation

Pyenv can be installed using Homebrew

1
2
brew update
brew install pyenv

Configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22

# (The below instructions are intended for common
# shell setups. See the README for more guidance
# if they don't apply and/or don't work for you.)

# Add pyenv executable to PATH and
# enable shims by adding the following
# to ~/.profile and ~/.zprofile' files
in your home directory:

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

# Load pyenv into the shell by adding
# the following to ~/.zshrc:

eval "$(pyenv init -)"

# Make sure to restart your entire logon session
# for changes to profile files to take effect.

Usage

Installing multiple python versions

1
2
pyenv install 3.6.0
pyenv install 3.7.0

Locating python installation directory

1
2
3
echo $(pyenv root)/versions

/Users/vinodpandey/.pyenv/versions

Finding installed python versions

1
pyenv versions

Configuring/selecting python version for a directory

1
2
3
pyenv local 3.6.0
python -V
Python 3.6.0