Skip to content

Instantly share code, notes, and snippets.

@navigatingbots
Forked from ZhangChen199102/.direnvrc
Last active June 14, 2025 10:42
Show Gist options
  • Save navigatingbots/37acd087a98700d90e3dc069cdec2346 to your computer and use it in GitHub Desktop.
Save navigatingbots/37acd087a98700d90e3dc069cdec2346 to your computer and use it in GitHub Desktop.

Revisions

  1. navigatingbots revised this gist Jun 14, 2025. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions direnv+pyenv+pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,7 @@
    1. Update `~/.zshrc`

    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
    echo 'eval "$(pyenv init --path)"' >> ~/.zshrc
    echo 'eval "$(pyenv init -)"' >> ~/.zshrc
    echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
    echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc
  2. @ZhangChen199102 ZhangChen199102 revised this gist Apr 1, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion direnv+pyenv+pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -52,4 +52,4 @@

    Now anytime you enter `./project_1/` or a directory under it, the virtualenv will automatically be activated, and environment variables will be setup.

    6. For IDE virtualenv setup, the virtualenv is under `~/.pyenv/versions/virtualenv_name/`
    6. For IDE virtualenv setup, the created virtualenv is under directory `~/.pyenv/versions/virtualenv_name/`
  3. Chen revised this gist Mar 6, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion direnv+pyenv+pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@

    1. Restart shell

    1. Add `.direnvrc` under `~/`
    1. Add [`.direnvrc`](https://gist.github.com/ZhangChen199102/da3133fc05e3b03afab405fdc3152fb3#file-direnvrc) under `~/`


    ## In use
  4. Chen revised this gist Aug 17, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion direnv+pyenv+pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
    echo 'eval "$(pyenv init -)"' >> ~/.zshrc
    echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
    echo 'eval "$(direnv hook bash)"' >> ~/.zshrc
    echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc

    1. Restart shell

  5. Chen revised this gist Aug 16, 2021. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions direnv+pyenv+pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -15,12 +15,12 @@

    brew install direnv

    1. Update `~/.bash_profile`
    1. Update `~/.zshrc`

    echo '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
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
    echo 'eval "$(pyenv init -)"' >> ~/.zshrc
    echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
    echo 'eval "$(direnv hook bash)"' >> ~/.zshrc

    1. Restart shell

  6. Chen revised this gist Dec 5, 2018. 1 changed file with 12 additions and 4 deletions.
    16 changes: 12 additions & 4 deletions direnv+pyenv+pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -33,15 +33,23 @@

    mkdir project_1

    2. Create `.envrc` under `./project_1` with environment variables declaration like:
    `export ENV_VARIBALE_NAME=bla`
    2. Create virtual environment:

    pyenv virtualenv 3.6.7 venv-name

    3. Enter the project directory, run this command to trust current environment, you only need to run this at this first time and once `.envrc` is updated.
    3. Create `.python-version` under `./project_1` with the virtual environment name created in step 2.

    venv-name
    4. Create `.envrc` under `./project_1` with environment variables declaration like:
    ```export ENV_VARIBALE_NAME=bla```


    5. Enter the project directory, run this command to trust current environment, you only need to run this at this first time and once `.envrc` is 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.

    4. For IDE virtualenv setup, the virtualenv is under `~/.pyenv/versions/virtualenv_name/`
    6. For IDE virtualenv setup, the virtualenv is under `~/.pyenv/versions/virtualenv_name/`
  7. Chen revised this gist Dec 5, 2018. 2 changed files with 2 additions and 15 deletions.
    14 changes: 0 additions & 14 deletions .envrc
    Original file line number Diff line number Diff line change
    @@ -1,14 +0,0 @@
    # python version will be used for this project.
    pyversion=3.6.4
    # virtualenv name
    pvenv=project1_env

    # use a certain pyenv version
    use python ${pyversion}
    # Create the virtualenv if not yet done
    layout virtualenv ${pyversion} ${pvenv}
    # activate it
    layout activate ${pvenv}-${pyversion}

    # add environment variable here
    export ENVIRONMENT_VARIABLE="first_environment_variable"
    3 changes: 2 additions & 1 deletion direnv+pyenv+pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,8 @@

    mkdir project_1

    2. Add `.envrc` under `./project_1`
    2. Create `.envrc` under `./project_1` with environment variables declaration like:
    `export ENV_VARIBALE_NAME=bla`


    3. Enter the project directory, run this command to trust current environment, you only need to run this at this first time and once `.envrc` is updated.
  8. Chen renamed this gist Feb 25, 2018. 1 changed file with 0 additions and 0 deletions.
  9. Chen revised this gist Feb 25, 2018. No changes.
  10. Chen revised this gist Feb 25, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions direnv + pyenv + pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,8 @@
    echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
    echo 'eval "$(direnv hook bash)"' >> ~/.bash_profile

    1. Restart shell

    1. Add `.direnvrc` under `~/`


  11. Chen revised this gist Feb 25, 2018. 1 changed file with 4 additions and 7 deletions.
    11 changes: 4 additions & 7 deletions direnv + pyenv + pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -16,14 +16,11 @@
    brew install direnv

    1. Update `~/.bash_profile`

    `echo '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`

    echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc
    echo '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

    1. Add `.direnvrc` under `~/`

  12. Chen revised this gist Feb 25, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions direnv + pyenv + pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,8 @@
    `echo 'eval "$(pyenv init -)"' >> ~/.bash_profile`
    `echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile`
    `echo 'eval "$(direnv hook bash)"' >> ~/.bash_profile`

    echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc

    1. Add `.direnvrc` under `~/`

  13. Chen revised this gist Feb 25, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions direnv + pyenv + pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,7 @@
    1. Update `~/.bash_profile`

    `echo '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`
  14. Chen revised this gist Feb 25, 2018. 4 changed files with 78 additions and 46 deletions.
    25 changes: 20 additions & 5 deletions .direnvrc
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,22 @@
    # See https://github.com/direnv/direnv/wiki/Python#-pyenv

    # use a certain pyenv version
    use_python() {
    local python_root=$HOME/.pyenv/versions/$1
    load_prefix "$python_root"
    layout_python "$python_root/bin/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}-${pyversion}
    fi
    pyenv local --unset
    }

    layout_activate() {
    if [ -n "$(which pyenv)" ]; then
    source $PYENV_ROOT/versions/$1/bin/activate
    fi
    }
    14 changes: 14 additions & 0 deletions .envrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # python version will be used for this project.
    pyversion=3.6.4
    # virtualenv name
    pvenv=project1_env

    # use a certain pyenv version
    use python ${pyversion}
    # Create the virtualenv if not yet done
    layout virtualenv ${pyversion} ${pvenv}
    # activate it
    layout activate ${pvenv}-${pyversion}

    # add environment variable here
    export ENVIRONMENT_VARIABLE="first_environment_variable"
    44 changes: 44 additions & 0 deletions direnv + pyenv + pyenv-virtualenv.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@

    ## Install and setup

    1. Install pyenv and pyenv-virtualenv

    brew install pyenv
    brew install pyenv-virtualenv

    2. Install different versions of python

    pyenv install 3.6.4
    pyenv install 3.6.0

    1. Install direnv

    brew install direnv

    1. Update `~/.bash_profile`

    `echo '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`

    1. Add `.direnvrc` under `~/`


    ## In use

    1. Create a project directory.

    mkdir project_1

    2. Add `.envrc` under `./project_1`


    3. Enter the project directory, run this command to trust current environment, you only need to run this at this first time and once `.envrc` is 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.

    4. For IDE virtualenv setup, the virtualenv is under `~/.pyenv/versions/virtualenv_name/`
    41 changes: 0 additions & 41 deletions pyenv + direnv.md
    Original file line number Diff line number Diff line change
    @@ -1,41 +0,0 @@
    ## Install

    1. Install pyenv

    brew install pyenv

    2. Install different versions of python on your machine

    pyenv install 3.6.4
    pyenv install 3.6.0

    1. Install direnv

    brew install direnv

    1. Add the following line at the end of the ~/.bashrc file:

    eval "$(direnv hook bash)"

    1. for other shells setup:
    [https://github.com/direnv/direnv#setup](https://github.com/direnv/direnv#setup)

    1. Create `.direnvrc` in `~/`


    ## In use

    1. Create a project directory.

    mkdir project_1

    2. Create `.envrc` under `./project_1`
    echo "use python 3.6.4" > project_1/.envrc
    echo "export ENVIRONMENT_VARIABLE=1" > project_1/.envrc

    3. Enter the project directory, run this command to trust current environment, you only need to run this at this first time and once `.envrc` is updated.

    cd projects_1/
    direnv allow

    Now anytime you enter `./project_1/` or a directory under it, the virtualenv will automatically be setup your environment variables.
  15. ChenZhang revised this gist Feb 24, 2018. 1 changed file with 41 additions and 0 deletions.
    41 changes: 41 additions & 0 deletions pyenv + direnv.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    ## Install

    1. Install pyenv

    brew install pyenv

    2. Install different versions of python on your machine

    pyenv install 3.6.4
    pyenv install 3.6.0

    1. Install direnv

    brew install direnv

    1. Add the following line at the end of the ~/.bashrc file:

    eval "$(direnv hook bash)"

    1. for other shells setup:
    [https://github.com/direnv/direnv#setup](https://github.com/direnv/direnv#setup)

    1. Create `.direnvrc` in `~/`


    ## In use

    1. Create a project directory.

    mkdir project_1

    2. Create `.envrc` under `./project_1`
    echo "use python 3.6.4" > project_1/.envrc
    echo "export ENVIRONMENT_VARIABLE=1" > project_1/.envrc

    3. Enter the project directory, run this command to trust current environment, you only need to run this at this first time and once `.envrc` is updated.

    cd projects_1/
    direnv allow

    Now anytime you enter `./project_1/` or a directory under it, the virtualenv will automatically be setup your environment variables.
  16. ChenZhang created this gist Feb 24, 2018.
    7 changes: 7 additions & 0 deletions .direnvrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    # See https://github.com/direnv/direnv/wiki/Python#-pyenv

    use_python() {
    local python_root=$HOME/.pyenv/versions/$1
    load_prefix "$python_root"
    layout_python "$python_root/bin/python"
    }