How to uninstall all unused packages in a conda virtual environment? How to uninstall all unused packages in a conda virtual environment? python python

How to uninstall all unused packages in a conda virtual environment?


conda clean --yes --all

will sanitize everything. But take note: if you ever want to do any type of --offline operations, don't use --all; be more selective.


@AgileBean I try an answer to your comment's question on why --packages gives you more results than --all. This is still related to the main question how to uninstall, hopefully.

The difference between

    conda clean --yes --all

and

    conda clean --yes --packages

is that the packages are only the extracted folders. All of the other files (.tar.bz2, .conda, that is: tarballs) are not cleaned by --packages.

If you want to clean only the tarballs, you would need

    conda clean --yes --tarballs

References:Anaconda Python: Delete .tar.gz in pkgs

Here is an example of the differences. Mind that --all includes --packages in a real run, but it does not show --packages results in dry-run (very strange!, see the following screenshot, it just stops at DryRunExit: Dry run. Exiting.)

conda clean --all --dry-run vs. conda clean --packages --dry-run

Which differences exist that could explain that you find more with --packages than with --all?

  1. As said before, my first guess is that you only used dry-run option which will not show you the cleaned --packages when you run conda clean --all --dry-run. Therefore see this real run from conda clean --all:

    conda clean --all

  2. The 2 warnings could be interesting:

    WARNING: C:\Users\Admin\.conda\pkgs does not exist                                                                                                                                           WARNING: C:\Users\Admin\AppData\Local\conda\conda\pkgs does not exist

    But if you do not dry-run, but really run --all, you get thesame, because --all includes the --packages and thus itswarnings as well. This, again, cannot be seen when you use dry-run.

  3. A good reason could be that you have once cleaned your packageswith --tarballs or that you have simply removed some tarballsmanually so that your unzipped packages outnumber your tarballs in the --dry-run.

  4. You might have unzipped a lot of packages manually into the cachefolder, e.g. the manual installations from git and all of the otherinstallations that do not offer conda / pip install and then again, in --dry-run, the --all exits without showing the --packages.

  5. Perhaps you find another thing in the docs?https://docs.conda.io/projects/conda/en/latest/commands/clean.html.It says about symbolic links: "WARNING: This does not check for packages installed using symlinks back to the package cache." As --packages is part of --all, this is still no explanation of your difference.

I guess that the reason for your --packages > --all issue is that conda clean --all --dry-run does not show the results of the --packages, although it cleans them as well, so that you do not actually have that issue ;).


For what it's worth, I noticed the following...

  • conda clean --all --dry-run gave me a rough total of 2GB
  • conda clean --packages --dry-run gave me a rough total of 6GB

So same discrepancy as observed by OP...

When I next did conda clean --tarballs --dry-run I noticed it also gave me 2GB, strange... Comparing output of first and last commands it seems conda clean --all --dry-run only showed me the tarballs, no mention of the packages

I went ahead, did conda clean --tarballs and then reran the conda clean --all --dry-run... guess what? It now showed the packages (after mentioning there were no tarballs, which is logical as I just cleaned them)

My conclusion... when there are still tarballs in the cache, conda clean --all --dry-run does not provide you the full picture of what will/could be removed