What is the pip cache, and is it safe to delete?

The pip cache holds downloaded Python packages and built wheels so reinstalling is quick, and it is safe to clear with pip cache purge because pip downloads again when needed.

Shiva ChandraMaker of Clean House · · 2 min read
Short answer

The pip cache is the folder where pip stores downloaded packages, locally built wheels and HTTP responses so repeat installs are fast. It is safe to clear. Run pip cache purge and pip downloads packages again the next time you install them. Installed packages in your environments are not affected.

Path
~/Library/Caches/pip
What it is
pip's cache of downloaded files and locally built wheels
Typical size
Hundreds of megabytes to several gigabytes; machine-learning wheels are large
Made by
pip (Python)
Safe to delete?
Safe to clear
Comes back?
Yes, pip downloads or rebuilds packages on the next install

What is in this folder?

On macOS pip uses ~/Library/Caches/pip, according to the pip documentation. It has a wheel cache for built packages and an HTTP cache for downloads. Compiling a package from source can take minutes, and the cache lets pip reuse the result.

The pip documentation also notes that the exact file structure is an implementation detail that can change between versions.

Is it safe to delete?

Yes. The cache only speeds up installs. Packages already installed in a virtual environment or in site-packages stay put. The cost is time: packages with a long compile step, such as ones with C extensions, take longer on the next install.

How do I clear it by hand?

  1. Close any running pip install.
  2. Check the size, then purge.
  3. Reinstall packages normally when you need them.
python3 -m pip cache info
python3 -m pip cache purge
pip cache remove <package> removes one package's wheels, and pip install --no-cache-dir skips the cache for one install.

How do I stop it growing?

Run pip cache purge now and then, or install with --no-cache-dir in disposable environments.

How Clean House handles it

Clean House recognizes the pip cache as downloaded Python packages made by pip, and marks it as something that comes back. It leaves the cache alone while a pip install is running, and the files go to the Trash before they are gone for good.

Questions

Is it safe to delete the pip cache?

Yes. pip downloads or rebuilds packages on the next install. Installed packages are unaffected.

How do I clear the pip cache?

Run pip cache purge. pip cache info shows its size and location first.

Where is the pip cache on Mac?

At ~/Library/Caches/pip. pip cache dir prints the path.

Sources

  1. pip Docs: pip cache
  2. pip Docs: Caching