Skip to content

Instantly share code, notes, and snippets.

@dokenzy
Created November 3, 2018 05:16
Show Gist options
  • Save dokenzy/b29fd30df92967a641371acf26a714d3 to your computer and use it in GitHub Desktop.
Save dokenzy/b29fd30df92967a641371acf26a714d3 to your computer and use it in GitHub Desktop.
pyenv + pyenv_virtualenv + direnv 설정
# -*- 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
  1. brew install pyenv pyenv-virtualenv direnv

  2. edit ~/.zshrc, ~/.zshenv, ~/.config/direnv/direnvrc

  3. go to project directory

  4. edit .envrc

  5. run direnv allow

DONE!

# 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment