how do you check to see if any conda environment is active with a flag

Viewed 342

How can I tell if any conda environment is active with a flag?

i.e. when I try to run

conda deactivate && conda env list

or when I run

conda activate && conda env list

they both output the same thing

# conda environments:
#
base                  *  /Users/name/opt/miniconda3
2 Answers

I found the answer myself. There is a CONDA_SHLVL environment variable.

[[ $CONDA_SHLVL == 1 ]] && echo "conda environment is active"

Another option would be to run

conda info but the output must be parsed

when a conda env is not active it will display

william‣ wmbp‣ ~ % conda info                                                                                                                                                                                                                                                                                                                                 

     active environment : None
     ...

In Mac OS, you can also use conda env list which will show all available environments with an asterisk next to the currently active one.

$ conda env list
# conda environments:
#
base                    /Users/yourname/miniconda3
dataEnv              *  /Users/yourname/miniconda3/envs/dataEnv
webParsing              /Users/yourname/miniconda3/envs/webParsing
Related