Conda: Remove All Installed Packages from Base/Root Environment

conda: remove all installed packages from base?

$conda clean --all
by using this command you can remove old packages. and then delete all environment and reset the

If I remove a conda environment will it automatically remove all packages?

Let's be more specific and remove the env foo located at anaconda3/envs/foo with

conda env remove -n foo

This usually deletes everything under anaconda3/envs/foo.

PyPI packages may stick around. If you previously used pip install in the environment, it can occasionally leave some residual things behind. If that's the case, you'll need to delete the anaconda3/envs/foo folder manually after conda env remove. Or you could try to pip uninstall any PyPI packages first1, to get a clean conda env remove result.

Conda also caches all packages, independent of whether or not they are currently in use. This would be under anaconda3/pkgs (usually). To additionally delete the packages no longer in use, one can use

conda clean -tp  # delete tarballs and unused packages

1: There is a command to programmatically remove all PyPI-installed packages from Conda environments in this answer.

Conda remove uninstalls more packages than expected

Workaround

I can't think of an automated way to do this, but if you absolutely must achieve this, then a hacky way to do it is:

  1. Remove only the package(s) you want:

    conda remove --force libtiff
  2. Trigger a consistency check to get a list of now broken packages:

    conda install -d python
  3. If there are packages, then iterate (i.e., remove them with Step 1); otherwise, you're done.

Actually, you're not done because now every time you attempt a change in the environment, every package that isn't a dependency of an explicit spec will be proposed for removal. Probably the next step is to:


  1. Export the resulting env:

    conda env export -n my_env > env.yaml
  2. Recreate the env:

    conda env remove -n my_env
    conda env create -n my_env -f env.yaml

Now all the packages will be explicit specs, which isn't necessarily a good thing either, but at least ensures they won't get removed on later updates.

Commentary

Personally, I think this is a bad idea and don't really see the motivation. I think it is much better an idea to start from the packages you know you need, place them in a YAML definition, and create envs from that.

Conda remove all environments (except root)

Removing all directories inside the envs subdirectory that resides inside conda does the job. This is generally in your user folder ~.

~\.conda\envs\

What is the difference between conda uninstall and conda remove?

There is no difference, they are the same command.

Check the help output of conda uninstall:

conda uninstall --help
usage: conda-script.py uninstall [-h] [-n ENVIRONMENT | -p PATH] [-c CHANNEL] [--use-local] [--override-channels]
[--repodata-fn REPODATA_FNS] [--all] [--features] [--force-remove] [--no-pin] [-C]
[-k] [--offline] [-d] [--json] [-q] [-v] [-y] [--dev]
[package_name [package_name ...]]

Alias for conda remove.
[...]

Note the Alias for conda remove.



Related Topics



Leave a reply



Submit