SoFunction
Updated on 2025-04-11

Example of method to clean up pip and conda caches

Clean uppipandcondaThe cache can help free up disk space and ensure that the installed packages are up to date.

1. Clean the pip cache

pipThe downloaded package will be cached locally to speed up subsequent installations. By default, the cache path is~/.cache/pip

Command to clean cache:

Clean up all pip download caches

pip cache purge

Clean up specific cache files or packages:

# List cached packagespip cache list

# Clean up specific packagespip cache remove <package-name>

Manually clean the cache:

If you cannot use the command to clean it up, you can manually delete the cache directory:

# Delete the default pip cache directoryrm -rf ~/.cache/pip

2. Clean the conda cache

condaThe default cache path is usually~/anaconda3/pkgsor~/miniconda3/pkgs(The specific path depends on your installation location).

Command to clean cache

Clean up all caches of conda downloads

conda clean --all

This command cleans up the following:

  • Downloaded package file (.tar.bz2
  • Unzipped package file
  • Old log files

Manually clean the cache:

If you need to clean up manually, you can delete files in the cache directory:

# Delete packages in the conda cache directoryrm -rf ~/anaconda3/pkgs/*
# orrm -rf ~/miniconda3/pkgs/*

3. Clean up redundant files in the virtual environment

In a virtual environment, there may be some redundant files or unused dependencies. You can use the following tools to clean up:

Use pip-autoremove to clean up unused packages

pip-autoremoveIt is a tool that can automatically remove unreliable packages in the virtual environment.

Install:

pip install pip-autoremove

use:

# Remove unreliable packagespip-autoremove <package-name> --yes

Use conda to clean up the environment

If you are usingcondaIn a virtual environment, unused packages can be cleaned with the following command:

conda clean --packages

This is the end of this article about the example method of cleaning pip and conda cache. For more information about cleaning pip and conda cache, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!