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?
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.
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.
NOTE: Only wheels downloaded over HTTPS are cached. If you are using a custom repo over plain old HTTP, the cache is disabled.
Newer Pip versions by default now cache downloads. See this documentation:
https://pip.pypa.io/en/stable/cli/pip_install/#caching
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
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With