Search code examples
pythondockerpip

What is pip's `--no-cache-dir` good for?


I've recently seen the --no-cache-dir being used in a Docker file. I've never seen that flag before and the help is not explaining it:

 --no-cache-dir              Disable the cache.
  1. Question: What is cached?
  2. Question: What is the cache used for?
  3. Question: Why would I want to disable it?

Solution

    1. Cached is: store away in hiding or for future use
    2. Used for
    • store the installation files(.whl, etc) of the modules that you install through pip
    • store the source files (.tar.gz, etc) to avoid re-download when not expired
    1. Possible Reason you might want to disable cache:
    • you don't have space on your hard drive
    • previously run pip install with unexpected settings
      • eg:
        • previously run export PYCURL_SSL_LIBRARY=nss and pip install pycurl
        • want new run export PYCURL_SSL_LIBRARY=openssl and pip install pycurl --compile --no-cache-dir
    • you want to keep a Docker image as small as possible

    Links to documentation

    https://pip.pypa.io/en/stable/topics/caching