howaboutqiu

如何重置一个 conda 环境

原文 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.

以下为 GPT-4o 翻译内容:

有时候会觉得整个 conda environment 已经无药可救了,干脆重新建一个吧。

可以用以下命令来克隆一个已有的环境:

conda create --name new_env --clone old_env

或者使用以下命令来从头创建一个新的环境:

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

然后回头清理一下旧环境:

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

如何清理 conda 本身呢?

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

以上。

#conda #snippet