Clearing the pip cache helps when repeated installs keep reusing stale downloads, when cached package data is taking more disk space than expected, or when a clean retry is needed after repository or build changes.
The pip cache contains HTTP responses from package indexes and locally built wheels, and python3 -m pip cache info shows both areas before removal. A full purge clears the cache for the active interpreter or virtual environment only, so the command sequence should match the pip context that is actually being used for installs.
Cache paths and directory names vary by operating system and pip version, and current upstream documentation notes that newer HTTP entries are stored under http-v2 instead of the older http directory. Overrides such as PIP_CACHE_DIR can redirect the cache elsewhere, so check the live location first and expect the next install or download to take longer after a purge.
Related: How to show the pip cache location
Steps to clear the pip cache:
- Show the active pip cache directory before removing anything.
$ python3 -m pip cache dir /Users/alex/Library/Caches/pip
If the reported path is not the cache that should be cleared, stop and confirm the active interpreter, virtual environment, or PIP_CACHE_DIR override first. On Windows, run py -m pip cache dir.
- Review the current cache summary so the HTTP cache path, wheel cache path, file counts, and sizes are known before the purge.
$ python3 -m pip cache info Package index page cache location (pip v23.3+): /Users/alex/Library/Caches/pip/http-v2 Package index page cache location (older pips): /Users/alex/Library/Caches/pip/http Package index page cache size: 517 kB Number of HTTP files: 6 Locally built wheels location: /Users/alex/Library/Caches/pip/wheels Locally built wheels size: 0 bytes Number of locally built wheels: 0
Current pip releases store new HTTP cache entries under http-v2, but upgraded environments can still show the older http path. pip cache list reports wheel entries only, so use pip cache info for the full cache view.
- Purge the active pip cache.
$ python3 -m pip cache purge Files removed: 6 (517 kB) Directories removed: 0
python3 -m pip cache purge clears both the HTTP cache and the wheel cache for the active pip context. If only one cached wheel is the problem, python3 -m pip cache remove <package> is a narrower alternative.
- Confirm that the active cache summary has returned to zero.
$ python3 -m pip cache info Package index page cache location (pip v23.3+): /Users/alex/Library/Caches/pip/http-v2 Package index page cache location (older pips): /Users/alex/Library/Caches/pip/http Package index page cache size: 0 bytes Number of HTTP files: 0 Locally built wheels location: /Users/alex/Library/Caches/pip/wheels Locally built wheels size: 0 bytes Number of locally built wheels: 0
The cache directory itself may remain in place after the purge. Zero sizes and zero file counts confirm that the active cache contents were cleared.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
