Python pip 的 `--no-cache-dir` 有什么用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45594707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is pip's `--no-cache-dir` good for?
提问by Martin Thoma
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
在 Docker 文件中使用。我以前从未见过那个标志,帮助也没有解释它:
--no-cache-dir Disable the cache.
- Question: What is cached?
- Question: What is the cache used for?
- Question: Why would I want to disable it?
- 问题:缓存是什么?
- 问题:缓存有什么用?
- 问题:我为什么要禁用它?
采纳答案by Stack
- Cached is: store away in hiding or for future use
- 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
- store the installation files(
- Possible Reasonyou might want to disable cache:
- you don't have space on your hard drive
- previously run
pip install
with unexpectedsettings- eg:
- previously run
export PYCURL_SSL_LIBRARY=nss
andpip install pycurl
- want new run
export PYCURL_SSL_LIBRARY=openssl
andpip install pycurl --compile --no-cache-dir
- previously run
- eg:
- 缓存是:隐藏起来或以备将来使用
- 用于
- 存储
.whl
您通过 pip 安装的模块的安装文件(等) - 存储源文件(
.tar.gz
等)以避免在未过期时重新下载
- 存储
- 您可能想要禁用缓存的可能原因:
- 你的硬盘上没有空间
- 以前
pip install
使用意外设置 运行- 例如:
- 以前运行
export PYCURL_SSL_LIBRARY=nss
和pip install pycurl
- 想要新的运行
export PYCURL_SSL_LIBRARY=openssl
和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
https://pip.pypa.io/en/stable/reference/pip_install/#caching– @emredjan https://pip.pypa.io/en/stable/reference/pip_install/- @mikea
回答by Philip Tzou
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.
我认为在--no-cache-dir
构建 Docker 镜像时有一个很好的理由使用它。缓存在 Docker 镜像中通常是无用的,您绝对可以通过禁用缓存来缩小镜像大小。
回答by PacketFiend
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.
禁用 pip 缓存的另一个原因 - 如果您以尚不存在的用户身份运行 pip,则将创建其主目录,但由 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.
我们在 chroot 中构建 Amazon AMI 时会发生这种情况 - pip 以构建器机器上存在的用户身份运行,但不在构建 AMI 的 chroot jail 中运行。这是有问题的,因为该特定用户现在无法 ssh 到刚刚构建的内容,因为他们无法读取他们的 .ssh 目录。
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.
我想不出任何其他原因 pip 会以不存在的用户身份运行,因此这在很大程度上是一种边缘情况。
回答by Zoe The Paranoid
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.
如果您的 DockerFile 中有 python 依赖项,请减小您的 docker 镜像大小,因为您的私有注册表/人工工厂或您的部署服务可能有大小限制。
回答by Harvey
I get permission error for installation of some pip packages if I don't use --no-cache-dir
option.
如果我不使用--no-cache-dir
选项,我会收到安装某些 pip 包的权限错误。
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.
chown /.cache
文件夹由于某种原因没有帮助,但--no-cache-dir
它可以正常工作。