Set Environment-Specific Variables in Anaconda

There are certain environment variables that are often set within a conda environment. It is actually pretty easy to automate the procedure of setting/unsetting those variables when activating/deactivating corresponding environments, though the documentation is scattered. Here is a quick summary.

Say conda (either Anaconda or Miniconda applies) is installed at $CONDA_PREFIX .There are two directories within which the scripts are sourced when activating/deactivating an environment:

  • $ENV_PREFIX/etc/conda/activate.d
  • $ENV_PREFIX/etc/conda/deactivate.d

where $ENV_PREFIX is normally $CONDA_PREFIX/envs/<env-name>.

(Those two directories may not be present by default). Simply create a script, say under each of the directories and do manipulation of environment variables therein.

Sample $ENV_PREFIX/etc/conda/activate.d/

export PYOPENCL_TEST='port'

Sample $ENV_PREFIX/etc/conda/deactivate.d/


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.