Never forget to activate that virtualenv or set that environment variable ever again...
-
Install pyenv
brew install pyenv
-
Install a few different pythons
pyenv install 3.6.0 pyenv install 3.5.2 pyenv install 2.7.who-cares
-
Install direnv
brew install direnv
-
If you're using zsh add the following to your
~/.zshrc
:echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc
-
If you're using bassh add the following to your
~/.bashrc
:echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
-
Copy
.direnvrc
into~/
You now have everything setup to use direnv.
Now, time to actually use it.
-
Create a directory, I usually put this in
~/workspace
, others prefer!/projects
.mkdir ~/projects/w00t
-
Create the file
~/projects/w00t/.envrc
echo "use python 3.6.0" > ~/projects/w00t/.envrc echo "export AN_ENVIRONMENT_VARIABLE=1" >> ~/projects/w00t/.envrc
-
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 and environment variable AN_ENVIRONMENT_VARIABLE
will be set.
w00t!