pip provides an on-by-default caching, designed to reduce the amount of time spent on duplicate downloads and builds.
It is safe to delete the user cache directory. It will simply cause pip to re-download all packages from PyPI.
The idea behind the pip cache is simple ,when you install a Python package using pip for the first time ,it gets saved on the cache . If you try to download/install the same version of the package on a second time ,pip will just use the local cached copy instead of retrieving it from the remote register .
.whl
, etc) of the modules that you install through pip.tar.gz
, etc) to avoid re-download when not expiredpip install
with unexpected settings
export PYCURL_SSL_LIBRARY=nss
and pip install pycurl
export PYCURL_SSL_LIBRARY=openssl
and pip install pycurl --compile --no-cache-dir
Links to documentation
https://pip.pypa.io/en/stable/reference/pip_install/#caching – @emredjan https://pip.pypa.io/en/stable/reference/pip_install/ - @mikea
I think there is a good reason to use --no-cache-dir
when you are building Docker images. The cache is usually useless in a Docker image, and you can definitely shrink the image size by disabling the cache.
Another reason to disable the pip cache - if you run pip as a user that does not yet exist, their home directory will be created, but owned by root.
This happens to us when building Amazon AMIs in a chroot - pip is being run as a user that exists on the builder machine, but not in the chroot jail where the AMI is being constructed. This is problematic as that specific user can now not ssh to what was just built as their .ssh directory is not readable by them.
I can't think of any other reason pip would be run as a user that doesn't exist though, so it's very much an edge case.
Reduce your docker image size if you're having python dependencies in your DockerFile, as your private registries/artifactories or your deployment servcies may have size limitation.
I get permission error for installation of some pip packages if I don't use --no-cache-dir
option.
Building wheels for collected packages: pyyaml, bottleneck, nvidia-ml-py3
WARNING: Building wheel for pyyaml failed: [Errno 13] Permission denied: '/home/user/.cache/pip/wheels/b1'
WARNING: Building wheel for bottleneck failed: [Errno 13] Permission denied: '/home/user/.cache/pip/wheels/92'
WARNING: Building wheel for nvidia-ml-py3 failed: [Errno 13] Permission denied: '/home/user/.cache/pip/wheels/7f'
chown /.cache
folder didn't help for some reason but with --no-cache-dir
it works ok.
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