-
Install pyenv and pyenv-virtualenv
brew install pyenv brew install pyenv-virtualenv -
Install different versions of python
pyenv install 3.6.4 pyenv install 3.6.0 -
Install direnv
brew install direnv -
Update
~/.bash_profileecho 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile echo 'eval "$(pyenv init -)"' >> ~/.bash_profile echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile echo 'eval "$(direnv hook bash)"' >> ~/.bash_profile -
Restart shell
-
Add
.direnvrcunder~/
-
Create a project directory.
mkdir project_1 -
Add
.envrcunder./project_1 -
Enter the project directory, run this command to trust current environment, you only need to run this at this first time and once
.envrcis updated.cd projects_1/ direnv allow
Now anytime you enter ./project_1/ or a directory under it, the virtualenv will automatically be activated, and environment variables will be setup.
- For IDE virtualenv setup, the virtualenv is under
~/.pyenv/versions/virtualenv_name/