-
brew install pyenv pyenv-virtualenv direnv
-
edit
~/.zshrc
,~/.zshenv
,~/.config/direnv/direnvrc
-
go to project directory
-
edit
.envrc
-
run
direnv allow
DONE!
# -*- mode: sh; -*- | |
# (rootdir)/.envrc : direnv configuration file | |
# see https://direnv.net/ | |
pyversion=3.7.1 | |
pvenv=my_python_project_env_name | |
# | |
use python ${pyversion} | |
# Create the virtualenv if not yet done | |
layout virtualenv ${pyversion} ${pvenv} | |
# activate it | |
layout activate ${pvenv} |
if command -v pyenv 1>/dev/null 2>&1; then | |
eval "$(pyenv init -)" | |
fi | |
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi |
export NVM_DIR="$HOME/.nvm" | |
[ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh" | |
# pyenv | |
export PYENV_VIRTUALENV_DISABLE_PROMPT=1 | |
# direnv | |
eval "$(direnv hook zsh)" | |
export EDITOR=code |
# FILE PATH: ~/.config/direnv/direnvrc | |
# ~/.config/direnv/direnvrc: Global configuration for direnv to make it compliant | |
# with pyenv -- see https://direnv.net/ | |
# | |
# Adapted from | |
# - https://github.com/direnv/direnv/wiki/Python#-pyenv and | |
# - https://github.com/direnv/direnv/wiki/Python#-virtualenvwrapper | |
# | |
# use a certain pyenv version | |
use_python() { | |
if [ -n "$(which pyenv)" ]; then | |
local pyversion=$1 | |
pyenv local ${pyversion} | |
fi | |
} | |
layout_virtualenv() { | |
local pyversion=$1 | |
local pvenv=$2 | |
if [ -n "$(which pyenv-virtualenv)" ]; then | |
pyenv virtualenv --force --quiet ${pyversion} ${pvenv} | |
fi | |
} | |
layout_activate() { | |
if [ -n "$(which pyenv)" ]; then | |
local pyenvprefix=$(pyenv prefix) | |
local pyversion=$(pyenv version-name) | |
local pvenv="$1" | |
source ${pyenvprefix}/envs/${pvenv}/bin/activate | |
fi | |
} |