How to let pip ignore incorrect cached packages

When installing required packages with pip, sometimes it uses cached packages, e.g., older versions of those packages which can cause compatibility issues.

One way to deal with it is deleting the cache directory for pip.

$ sudo rm -rf ~/.cache/pip

Then we can redo the pip install, for instance using a requirement.txt file

$ pip install -r requirements.txt


With pip 20.1 or later, you can find the full path for your operating system easily by typing this in the command line:

$ pip cache remove matplotlib: removes all wheel files related to matplotlib from pip's cache.

$ pip cache purge: to clear all wheel files from pip's cache.

$ pip cache dir: to get the location of the cache.


If you want to not use the pip cache for some reason (which is a bad idea, according the official docs), your options are:

$ pip install --no-cache-dir <package>: install a package without using the cache, for just this run.

$ pip config set global.no-cache-dir false: configure pip to not use the cache "globally" (in all commands).


No comments:

Post a Comment