Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cache downloaded PIP packages [duplicate]

Tags:

python

pip

How do you prevent PIP from re-downloading previously downloaded packages? I'm testing the install of matplotlib, an 11MB package that depends on several distro-specific packages. Everytime I run pip install matplotlib, it re-downloads matplotlib. How do I stop this?

like image 397
Cerin Avatar asked Apr 26 '12 15:04

Cerin


People also ask

How do I delete cached pip packages?

If you want to force pip to clear out its download cache and use the specific version you can do by using --no-cache-dir command. If you are using an older version of pip than upgrade it with pip install -U pip. This will help you clear pip cache.

How do I clean my pip?

Uninstalling/removing Python packages using Pip To uninstall, or remove, a package use the command '$PIP uninstall <package-name>'. This example will remove the flask package.


2 Answers

NOTE: Only wheels downloaded over HTTPS are cached. If you are using a custom repo over plain old HTTP, the cache is disabled.

For new Pip versions:

Newer Pip versions by default now cache downloads. See this documentation:

https://pip.pypa.io/en/stable/cli/pip_install/#caching

For old Pip versions:

Create a configuration file named ~/.pip/pip.conf, and add the following contents:

[global] download_cache = ~/.cache/pip 

In one command:

printf '[global]\ndownload_cache = ~/.cache/pip\n' >> ~/.pip/pip.conf 
like image 86
Flimm Avatar answered Sep 22 '22 18:09

Flimm


You can use a specific environment variable PIP_DOWNLOAD_CACHE and make it point to a directory where your packages will be stored. If they are to be installed again, they will be taken from this directory.

There seems to be also an additional option for PIP pip --download-cache which ought to do something similar, but I have never tried it myself. For your example, to avoid re-downloading matplotlib every time, you would do the following:

pip install --download-cache /path/to/pip/cache matplotlib 

Does that answer your question?

like image 24
Charles Menguy Avatar answered Sep 19 '22 18:09

Charles Menguy