-
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
~/.zshrcecho 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc echo 'eval "$(pyenv init -)"' >> ~/.zshrc echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc -
Restart shell
-
Add
.direnvrcunder~/
-
Create a project directory.
mkdir project_1 -
Create virtual environment:
pyenv virtualenv 3.6.7 venv-name -
Create
.python-versionunder./project_1with the virtual environment name created in step 2.venv-name -
Create
.envrcunder./project_1with environment variables declaration like:export ENV_VARIBALE_NAME=bla -
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/