Python – Restore Anaconda as you did the first installation

Restore Anaconda as you did the first installation… here is a solution to the problem.

Restore Anaconda as you did the first installation

I

created two environments in Users/user/conda/envs that I no longer need. I see that there are also pkgs in Users/user/conda and they are both Users/user/conda/envs and Users/user/conda/pkgs really take up a lot of my storage space. I want to delete both environments.

  1. conda remove -n env_name --all Does the environment and all packages in its environment also remove? Or just delete the environment?

  2. Can I delete the folders pkgs and env directly from users/user without affecting the base environment?

  3. How do I restore Anaconda (with only the base environment and default packages) as I did on the first installation?

Or do I need to uninstall Anaconda and reinstall it?

Solution

Specific answer

  1. Does conda remove -n env_name --all delete the environment and all its installed packages under its environment too? Or does it only delete the environment?

It deletes the environment my_env, which includes the extracted libraries and the env/env_name directory. It does not delete the cached tarball in the conda/pkgs directory.

  1. Can I delete directly folder pkgs and env from Users/user without affect the base environment?

Yes. Note, however, that if you are using a soft link, deleting the pkgs directory may damage the environment. You can check if soft link is enabled

conda config --show allow_softlinks always_softlink

Although this does not tell if any are in use.

In addition, Conda packages can contain pre-unlink scripts, which may contain code that is expected to be evaluated during package removal. Deleting the environment directly ignores such protocols and may result in null references.

In general, I recommend using the commands available in the CLI instead of deleting folders. If you want to delete an environment, you should use the command in (1). If you want to delete cached packages, you should use conda clean (use the –-help flag to see the available options).

  1. How can one revert Anaconda like the first time installed (contain only base environment and the default packages)?

Similarly, you can use conda remove --all to remove other environments. For base, you can use

to restore it to its original state

conda install -n base --revision 0

However, I would have noticed that many users reported that this didn’t work, or at least run into issues if they went back too far. Instead, use conda list --revisions to review the revision history and select a state that deletes what you don’t want.

General recommendations

Mini forged

Since you seem to want a complete rest, I recommend uninstalling Anaconda completely. However, since you seem to be primarily concerned with space, rather than reinstalling Anaconda, consider switching to a Miniforge variant , which includes only the Conda package manager and the minimal infrastructure that supports it. Then create an environment that contains only the packages you actually need. You can still use conda clean --tarballs to minimize cached downloads, but with Miniforge, your footprint should be much smaller than a full Anaconda distribution.

Manage the environment

As a general rule of thumb, I recommend using base only to install Conda infrastructure (e.g., conda, mamba, conda-build, boa) and targeting the specific package environment you need (e.g. TensorFlow, PyTorch) uses a separate environment. In my experience, this helps keep your base more stable and allows you to divide potential package conflicts and end specific projects by clearing the environment when you no longer need them.

Related Problems and Solutions