I need to install psycopg2 v2.4.Best Answerpecifically. 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?

19 s
19

With pip 20.1 or later, you can do:

  • 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).

Some history around this question (puts on pip maintainer hat):

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>)

Back then, yes, passing --no-cache-dir was the only option to avoid this bug. So… it’s a bit unfortunate that this is the top search result on “pip cache remove”. 🙂

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. This was always possible by manually editting the relevant files, but this surfaced that ability to the command line. Details on pip’s configuration mechanisms is available here.

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

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *