howaboutqiu

How to reset a conda environment

Sometimes we just feel like the environment is beyond repair, and we want to start over.

We use the following to clone an existing environment:

conda create --name new_env --clone old_env

Or we can use the following to create a new environment from scratch:

conda activate old_env
conda env export > environment.yml
conda deactivate

conda create --name new_env
conda activate new_env

conda env update --name root --file environment.yml

Then we go back to clean up the old env:

pip freeze | grep -v conda > requirements.txt
pip uninstall -r requirements.txt -y

And how to clean up conda itself?

conda clean --dry-run --all
conda clean --all -y

And we are done.

#conda #snippet