Question

[Solved] Removing pip’s cache?

I need to install psycopg2 v2.4.1 specifically. I accidentally did:

 pip install psycopg2

Instead of:

 pip install psycopg2==2.4.1

That installs 2.4.4 instead of the earlier version.

Now even after I pip uninstall psycopg2 and attempt to reinstall with the correct version, it appears that pip is re-using the cache it downloaded the first time.

How can I force pip to clear out its download cache and use the specific version I’m including in the command?

Enquirer: Geuis

||

Solution #1:

If using pip 6.0 or newer, try adding the --no-cache-dir option.

If using pip older than pip 6.0, upgrade it with pip install -U pip.

Respondent: sholsapp

Solution #2:

Clear the cache directory where appropriate for your system

Linux and Unix

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

OS X

~/Library/Caches/pip

Windows

%LocalAppData%pipCache

UPDATE

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 dir

Example output on my Ubuntu installation:

? pip3 cache dir
/home/tawanda/.cache/pip
Respondent: Dr Manhattan

Solution #3:

From documentation at https://pip.pypa.io/en/latest/reference/pip_install.html#caching:

Starting with v6.0, pip provides an on-by-default cache which
functions similarly to that of a web browser. While the cache is on by
default and is designed do the right thing by default you can disable
the cache and always access PyPI by utilizing the --no-cache-dir
option.

Respondent: dafeda

Solution #4:

(pip maintainer here!)

The specific issue of “installing the wrong version due to caching” issue mentioned in the question was fixed in pip 1.4 (back in 2013!):

Fix a number of issues related to cleaning up and not reusing build directories. (#413, #709, #634, #602, #939, #865, #948)

Since pip 6.0 (back in 2014!), pip install, pip download and pip wheel commands can be told to avoid using the cache with the --no-cache-dir option. (eg: pip install --no-cache-dir <package>)

Since pip 10.0 (back in 2018!), a pip config command was added, which can be used to configure pip to always ignore the cache — pip config set global.cache-dir false configures pip to not use the cache “globally” (i.e. in all commands).

Since pip 20.1, pip has a pip cache command to manage the contents of pip’s cache.

  • pip cache purge removes all the wheel files in the cache.
  • pip cache remove matplotlib selectively removes files related to a matplotlib from the cache.

In summary, pip provides a lot of ways to tweak how it uses the cache:

  • pip install --no-cache-dir <package>: install a package without using the cache, for just this run.
  • pip config set global.cache-dir false: configure pip to not use the cache “globally” (in all commands)
  • pip cache remove matplotlib: removes all wheel files related to matplotlib from pip’s cache.
  • pip cache purge: to clear all files from pip’s cache.
Respondent: pradyunsg

Solution #5:

pip can install a package ignoring the cache, like this

pip --no-cache-dir install scipy
Respondent: Yihe

Solution #6:

On Ubuntu, I had to delete /tmp/pip-build-root.

Respondent: Jace Browning

Solution #7:

Since pip 20.1b1, which was released on 21 April 2020 and “added pip cache command for inspecting/managing pip’s wheel cache”, it is possible to 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.

Respondent: Bence Mélykúti

Solution #8:

If you like to set the --no-cache-dir option by default, you can put this into pip.conf:

[global]
no-cache-dir = false

Note 1: It’s confusing, but to enable the no-cache-dir option you actually have to set it to false. Pretty silly if you ask me… but that’s how it is. There is a github issue to fix this.

Note 2: The location of pip.conf depends on your OS. See the documentation for more info.

Respondent: Rotareti

Solution #9:

I just had a similar problem and found that the only way to get pip to upgrade the package was to delete the $PWD/build (%CD%build on Windows) directory that might have been left over from a previously unfinished install or a previous version of pip (it now deletes the build directories after a successful install).

Respondent: dhobbs

Solution #10:

On archlinux pip cache is located at ~/.cache/pip, I could solve my issue by removing the http folder inside it.

Respondent: eneepo

Solution #11:

On my mac I had to remove the cache directory ~/Library/Caches/pip/

Respondent: matlads

Solution #12:

On Windows 7, I had to delete %HOMEPATH%/pip.

Respondent: Jace Browning

Solution #13:

If using virtualenv, look for the build directory under your environments root.

Respondent: Vajk Hermecz

Solution #14:

I had to delete %TEMP%pip-build On Windows 7

Respondent: Mikhail M

Solution #15:

On Mac OS (Mavericks), I had to delete /tmp/pip-build/

Respondent: Marcelo Soares

Solution #16:

A better way to do it is to delete the cache and rebuild it. In this way, if you install it again for other virtualenv, it will use the cache instead of building every time when you install it.

For example, when you install it, it will say it uses cached wheel,

Processing <some_prefix>/Library/Caches/pip/wheels/d0/c4/e4/e49fd07bca8dda00dd6b4bbc606aa05a25aacb00d45747a47a/horovod-0.19.3-cp37-cp37m-macosx_10_9_x86_64.wh

Just delete that one and restart your install.

Respondent: Izana

Solution #17:

Simply

rm -d -r "$(pip cache dir)"
Respondent: takelushi

Solution #18:

(…) it appears that pip is re-using the cache (…)

I’m pretty sure that’s not what’s happening. Pip used to (wrongly) reuse build directory not cache. This was fixed in version 1.4 of pip which was released on 2013-07-23.

Respondent: Piotr Dobrogost

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy