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 modify 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, 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.d/env_vars.sh
Populate the files
./etc/conda/activate.d/env_vars.sh <File>
#!/bin/sh
export MY_KEY='secret-key-value'
export MY_FILE=/path/to/my/file/
./etc/conda/deactivate.d/env_vars.sh <File>
#!/bin/sh
unset MY_KEY
unset MY_FILE
Will Warner
Thank you very much for this great blog post. I added the information to the conda documentation:
http://conda.pydata.org/docs/using/envs.html#saved-environment-variables
You and everyone else in the conda community are always welcome to submit GitHub issues or pull requests to conda and the conda documentation:
https://github.com/conda/conda-docs
Again, thank you for posting, and I’m very glad to see you’re finding conda useful!
benjaminmgross
Will,
Thanks so much for reading and putting it into the documentation!
Mike Palmer
In some lines of your instructions aboce you wrote “deactivate/” when you meant “deactivate.d/”.
Thanks for your help!
benjaminmgross
Mike,
I updated the post to fix the errors you mentioned.
Thanks for catching them!