Virtual Environments

Pyenv and different Python versions

Pyenv is a Python Version Management tool. If you want to change your global Python version, install and manage easily multiple versions, use project specific ones and create/manage virtualenvs, this is the right tool for you.

  • Install with curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

  • Add the following lines to ~/.bashrc:

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
  • Update your bashrc: source ~/.bashrc

  • Update pyenv: pyenv update

Features:

  • Check the global Python: pyenv global

  • List available versions: pyenv versions

  • Install Python 3.7.0: pyenv install 3.7.0

  • Change global Python version to 3.7.0: pyenv global 3.7.0

  • Define a project-specific Python version (e.g. 3.7.0):

    mkdir project_folder
    cd project_folder
    pyenv local 3.7.0
    

To deal with virtual environments using pyenv you need to install pyenv-virtualenv by:

git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
source ~/.bashrc

To create, activate and deactivate a virtualenv:

mkdir virtual_env
cd virtual_env
pyenv virtualenv 3.7.0 venv
pyenv activate venv
pyenv deactivate