47

I have limited space on my server, and I am thinking to delete the cache of the PIP. I am not sure if its safe to delete or not.

ls  ~/.cache/pip/

Contains following dir/files.

http  selfcheck.json  wheels

Version

$ pip -V
pip 7.1.2 from /usr/local/lib/python2.7/dist-packages/pip-7.1.2-py2.7.egg (python 2.7)

Please advise.

A.J.
  • 8,557
  • 11
  • 61
  • 89

2 Answers2

86

Since pip 20.1b1, which was released on 21 April 2020 and "added pip cache command for inspecting/managing pip’s wheel cache", you no longer need to. Instead, you can issue this command:

pip cache purge

The reference guide is here:
https://pip.pypa.io/en/stable/reference/pip_cache/
The corresponding pull request is here.

Bence Mélykúti
  • 1,431
  • 2
  • 10
  • 7
  • 20
    Nice new feature. And `purge` does not remove my `http` cache, which is 400MB+ on my system macOS 10.15.4+pyenv+conda – laviex May 02 '20 at 02:55
  • 1
    Mine is at 4.1GB after doing 2 days of Unity ML setup and training... – Nevaran May 20 '21 at 17:26
  • 1
    It looks like this purge cmd now includes the http cache as of Oct 2020: https://github.com/pypa/pip/pull/8910 – A__ Aug 09 '21 at 17:37
27

According to pip's caching documentation from version 6 you can use the --no-cache-dir option.

But that didn't help me as I was using a wrapper (pinax starter projects) that runs pip in the background to install several packages. Since I kept getting an pip.exceptions.HashErrors ('hashes don't match the requirement file) and I didn't want to temper with its code I renamed the pip cache folder and tried running my wrapper again. Once I noticed there weren't issues I proceeded to delete the entire cache pip folder. I haven't had any problem after that. So I can assume it is entirely a safe operation to delete pip's cache folder.

These are the locations where you can find your pip cache:

Unix

~/.cache/pip and it respects the XDG_CACHE_HOME directory.

OS X

~/Library/Caches/pip.

Windows

\pip\Cache

BringBackCommodore64
  • 4,910
  • 3
  • 27
  • 30
  • 7
    At least in Windows 7 and Windows 10, I find pip's cache in C:\Users\\AppData\Local\pip\cache. – DDay Dec 11 '18 at 22:08
  • 1
    Note: you can find pip's caching directory using this command `python -m pip cache dir` in Linux/MacOS, and `py -m pip cache dir` in Windows. See [here](https://pip.pypa.io/en/stable/cli/pip_cache/#pip-cache) for info – DryLabRebel Apr 13 '22 at 21:52