How to cache downloaded PIP packages [duplicate]

Solution 1:

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

Solution 2:

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?