Skip to content

Instantly share code, notes, and snippets.

@gregnewman
Forked from alexhayes/ pyenv+direnv on OSX.md
Created June 18, 2021 13:07
Show Gist options
  • Save gregnewman/5b006494d570145b1da037581ef8423c to your computer and use it in GitHub Desktop.
Save gregnewman/5b006494d570145b1da037581ef8423c to your computer and use it in GitHub Desktop.

Revisions

  1. @alexhayes alexhayes revised this gist Feb 22, 2017. No changes.
  2. @alexhayes alexhayes revised this gist Feb 22, 2017. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions pyenv+direnv on OSX.md
    Original file line number Diff line number Diff line change
    @@ -8,25 +8,25 @@ Never forget to activate that virtualenv or set that environment variable ever a

    brew install pyenv

    2. Install a few different pythons
    1. Install a few different pythons

    pyenv install 3.6.0
    pyenv install 3.5.2
    pyenv install 2.7.who-cares

    3. Install direnv
    1. Install direnv

    brew install direnv

    4. If you're using zsh add the following to your `~/.zshrc`:
    1. If you're using zsh add the following to your `~/.zshrc`:

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

    5. If you're using bassh add the following to your `~/.bashrc`:
    1. If you're using bassh add the following to your `~/.bashrc`:

    echo 'eval "$(direnv hook bash)"' >> ~/.bashrc

    6. Copy `.direnvrc` into `~/`
    1. Copy `.direnvrc` into `~/`

    You now have everything setup to *use* direnv.

  3. @alexhayes alexhayes renamed this gist Feb 22, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @alexhayes alexhayes renamed this gist Feb 22, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @alexhayes alexhayes revised this gist Feb 22, 2017. 1 changed file with 27 additions and 6 deletions.
    33 changes: 27 additions & 6 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,55 @@
    # Setting up Python on OSX
    # Awesomely easy virtualenvs on OSX using pyenv and direnv

    Never forget to activate that virtualenv or set that environment variable ever again...

    ## Install

    1. Install pyenv
    brew install pyenv

    brew install pyenv

    2. Install a few different pythons

    pyenv install 3.6.0
    pyenv install 3.5.2
    pyenv install 2.7.who-cares

    3. Install direnv

    brew install direnv

    4. If you're using zsh add the following to your `~/.zshrc`:

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

    5. If you're using bassh add the following to your `~/.bashrc`:

    echo 'eval "$(direnv hook bash)"' >> ~/.bashrc

    6. Copy `.direnvrc` into `~/`

    You now have everything setup to *use* direnv.

    ## In use

    Now, time to actually use it.

    1. Create a directory, I usually put this in `~/workspace`, others prefer `!/projects`.

    mkdir ~/projects/w00t

    2. Create the file `~/projects/w00t/.envrc`

    echo "use python 3.6.0" > ~/projects/w00t/.envrc
    echo "export AN_ENVIRONMENT_VARIABLE=1" >> ~/projects/w00t/.envrc

    3. Go into that directory and say "yes, I trust this .envrc". You only need to do this when your `.envrc` file changes.

    cd ~/projects/w00t
    direnv allow
    This will cause a new python virtualenv to be created in `~/projects/w00t/.direnv`

    Now anytime you `cd` into `~/projects/w00t` or a directory below that the virtualenv will automatically be enabled for you.

    w00t!
    This will cause a new python virtualenv to be created in `~/projects/w00t/.direnv`

    Now anytime you `cd` into `~/projects/w00t` or a directory below that the virtualenv will automatically be enabled for you and environment variable `AN_ENVIRONMENT_VARIABLE` will be set.

    w00t!
  6. @alexhayes alexhayes created this gist Feb 22, 2017.
    34 changes: 34 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    # Setting up Python on OSX

    1. Install pyenv
    brew install pyenv
    2. Install a few different pythons
    pyenv install 3.6.0
    pyenv install 3.5.2
    pyenv install 2.7.who-cares
    3. Install direnv
    brew install direnv
    4. If you're using zsh add the following to your `~/.zshrc`:
    echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc
    5. If you're using bassh add the following to your `~/.bashrc`:
    echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
    6. Copy `.direnvrc` into `~/`

    You now have everything setup to *use* direnv.

    Now, time to actually use it.

    1. Create a directory, I usually put this in `~/workspace`, others prefer `!/projects`.
    mkdir ~/projects/w00t
    2. Create the file `~/projects/w00t/.envrc`
    echo "use python 3.6.0" > ~/projects/w00t/.envrc
    3. Go into that directory and say "yes, I trust this .envrc". You only need to do this when your `.envrc` file changes.
    cd ~/projects/w00t
    direnv allow
    This will cause a new python virtualenv to be created in `~/projects/w00t/.direnv`

    Now anytime you `cd` into `~/projects/w00t` or a directory below that the virtualenv will automatically be enabled for you.

    w00t!


    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"
    }