Pyenv Examples: Managing multiple Python versions and Virtualenvs

Pyenv Examples: Managing multiple Python versions and Virtualenvs

Last updated:
Table of Contents

Create virtualenv

$ pyenv virtualenv my-venv

Create virtualenv with python version

Create a virtualenv using a specific python version.

$ pyenv virtualenv 3.7.16 my-venv

Activate virtualenv

To activate a virtualenv called my-venv:

$ pyenv activate my-venv

Set default virtualenv for directory

Use pyenv local my-venv.

This will create a hidden .python-version file (should not be versioned).

The virtualenv will be activated automatically every time you cd to that directory (without the need to call pyenv activate)

$ pyenv local my-venv

Virtualenv location

For virtualenv my-venv:

  • on MacOS
  ~/.pyenv/versions/my-venv

Install python version

$ pyenv install 3.9

List python versions

$ pyenv versions

Dialogue & Discussion