Pyenv Examples: Managing multiple Python versions and Virtualenvs
Last updated:Table of Contents
- Create virtualenv
- Create virtualenv with python version
- Activate virtualenv
- Set default virtualenv for directory
- List virtualenvs
- Virtualenv directory location
- Install python version
- List python versions
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
List virtualenvs
$ pyenv virtualenvs
Virtualenv directory location
For virtualenv my-venv
:
- on MacOS
~/.pyenv/versions/my-venv
Install python version
$ pyenv install 3.9
List python versions
$ pyenv versions