Check what conda environment is currently activated

Viewed 15038

I'm wondering if there is an easy way to check which conda environment is currently activated.

I know you can do conda env list and the active environment will be printed with a *. However, I would like to do this programmatically as an input into an else if statement.

parsing the output of conda env list is rather inconvenient so I hope there is an easier way

3 Answers

When a conda environment is activated, it will export following related environment variables:

  • $CONDA_DEFAULT_ENV, name of current activated env
  • $CONDA_PREFIX, path to the current activate env

The current environment is stored in the environment variable, $CONDA_DEFAULT_ENV. So,

echo $CONDA_DEFAULT_ENV

will give the name of the current conda environment.

conda info --envs

This will print all the conda environments. The current environment will have an asterisk( * ) in front of it's name.
Related