如何防止PIP重新下载已经下载的软件包?我正在安装一个11MB的matplotlib软件包,它依赖于几个特定于发行版的软件包。每次运行pip install matplotlib
时,它都会重新下载matplotlib。我该如何停止这个过程?
注意: 只有通过HTTPS下载的包才会被缓存。如果你使用的是自定义库并通过普通的HTTP下载,缓存将被禁用。
新版本的Pip默认现在缓存下载内容。请查阅此文档:
https://pip.pypa.io/en/stable/topics/caching/
创建一个名为~/.pip/pip.conf
的配置文件,并添加以下内容:
[global]
download_cache = ~/.cache/pip
一条命令搞定:
printf '[global]\ndownload_cache = ~/.cache/pip\n' >> ~/.pip/pip.conf
您可以使用特定的环境变量PIP_DOWNLOAD_CACHE,将其指向一个存储包的目录。如果它们需要再次安装,则将从此目录中获取。
似乎还有一个额外的选项 pip --download-cache
可以做类似的事情,但我自己从未尝试过。对于您的示例,为了避免每次重新下载matplotlib
,您可以执行以下操作:
pip install --download-cache /path/to/pip/cache matplotlib
那是否解答了您的问题?
.tar
(或者可能是zip?)文件作为包,使用easy_install
将首先尝试使用该文件。 - Wayne Werner您可以
# download and extract package to build path
pip install --no-install matplotlib
# the build path could be found by
pip install --help|grep Unpack\ packages\ into -A 2
# then rm pip-delete-this-directory.txt inside the build path
# this prevent pip from removing package from the build directory after install
# you could check the content of the file
rm build/pip-delete-this-directory.txt
# from now on you could install matplotlib quickly
# this uses single build directory
# and can speed up compiling by caching intermediate objects.
pip install --no-download matplotlib
pip install -d dir_for_packages matplotlib
然后通过解压和python setup install
安装它。
pip install --download-cache
的工作方式类似,但有额外的检查:首先从网络上搜索目标软件包的最新版本或指定版本,如果搜索结果并且缓存目录中存在缓存软件包,则使用缓存软件包而不是下载。例如,
pip install --download-cache . pymongo
将下载pymongo包到当前目录:
http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fp%2Fpymongo%2Fpymongo-2.1.1.tar.gz
http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fp%2Fpymongo%2Fpymongo-2.1.1.tar.gz.content-type