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 | bash

  • Add the following lines to ~/.bashrc:

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

  • Update pyenv: pyenv update


  • 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 ~/.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