Skip to content

Instantly share code, notes, and snippets.

@benjaminmgross
Created August 11, 2015 15:56
Show Gist options
  • Save benjaminmgross/6d8c3928416cc77058c9 to your computer and use it in GitHub Desktop.
Save benjaminmgross/6d8c3928416cc77058c9 to your computer and use it in GitHub Desktop.
# `conda` env vars
## Quick `gist` to setup `conda` env variables
I try to keep `virtualenv` and `conda` going to ensure I stay versed in both virtual environment
methodologies. In `virtualenv` I can simply moding the script located in `$PATH/bin/activate` where
`$PATH` is the path to the virtual environment I'm working on. However, the process in `conda` is a
little more involved (but also straightforward, as all things `conda` seem to be).
## Create `activate / deactivate` directories
If `$PATH` is the directory for the conda environment, let's use for example, `my_env`. So:
$ echo $PATH
/home/benjaminmgross/anaconda/envs/my_env/
I would now want to follow the guidance provided on [this stackoverflow post](http://stackoverflow.com/questions/31598963/how-to-set-specific-environment-variables-when-activating-conda-environment), where we need to create the two following directories:
$ cd PATH
$ mkdir -p ./etc/conda/activate.d
$ mkdir -p ./etc/conda/deactivate.d
## Create the `env_vars.sh` files
$ touch ./etc/conda/activate.d/env_vars.sh
$ touch ./etc/conda/deactivate/env_vars.sh
## Populate the files
./etc/conda/activate/env_vars.sh
#!/bin/sh
export MY_KEY='secret-key-value'
export MY_FILE=/path/to/my/file/
./etc/conda/deactivate/env_vars.sh
#!/bin/sh
unset MY_KEY
unset MY_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment