Export all created conda environments

Viewed 925

I know how to export a specific conda environment:

conda activate myenv
conda env export > myenv.yaml

But how can I automatically export all created conda environments (in separate yaml files, whose name corresponds to the name of the environment)?

1 Answers

You don't need to activate the environment. conda env export accepts the argument -n <env name> which you can combine with a for loop over the output of conda list:

for env in $(conda env list | cut -d" " -f1); do 
   if [[ ${env:0:1} == "#" ]] ; then continue; fi;
   conda env export -n $env > ${env}.yml
done
Related