如何使用pip从本地缓存安装? [英] How do I install from a local cache with pip?
问题描述
我在不同的 virtualenv 环境中安装了许多相同的软件包.有没有一种方法可以下载一次软件包,然后从本地缓存中安装 pip ?
I install a lot of the same packages in different virtualenv environments. Is there a way that I can download a package once and then have pip install from a local cache?
这将减少下载带宽和时间.
This would reduce download bandwidth and time.
推荐答案
更新后的答案2015年11月19日
根据 Pip文档:
从v6.0开始,pip默认提供一个on缓存,其功能类似于Web浏览器.在默认情况下,当缓存处于打开状态并且被设计为默认情况下,做正确的事时,您可以禁用缓存并始终使用
--no-cache-dir
选项访问PyPI.
Starting with v6.0, pip provides an on by default cache which functions similarly to that of a web browser. While the cache is on by default and is designed do the right thing by default you can disable the cache and always access PyPI by utilizing the
--no-cache-dir
option.
因此,更新的答案是,如果要下载缓存,则仅使用pip及其默认值.
Therefore, the updated answer is to just use pip with its defaults if you want a download cache.
从 pip新闻 ,版本0.1.4:
From the pip news, version 0.1.4:
增加了对环境变量$ PIP_DOWNLOAD_CACHE的支持,该变量将缓存程序包下载,因此以后的安装将不需要大量下载.仍然需要网络访问权限,但是使用此功能时只能避免一些下载.
Added support for an environmental variable $PIP_DOWNLOAD_CACHE which will cache package downloads, so future installations won’t require large downloads. Network access is still required, but just some downloads will be avoided when using this.
要利用这一点,我在~/.bash_profile
中添加了以下内容:
To take advantage of this, I've added the following to my ~/.bash_profile
:
export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache
或者,如果您使用的是Mac:
or, if you are on a Mac:
export PIP_DOWNLOAD_CACHE=$HOME/Library/Caches/pip-downloads
注释
- 如果检测到软件包的较新版本,则将其下载并添加到
PIP_DOWNLOAD_CACHE
目录中.例如,我现在有很多Django软件包. - 这并不能消除对网络访问的需求,如点子新闻,因此这不是在飞机上创建新的
virtualenvs
的答案,但这仍然很棒.
- If a newer version of a package is detected, it will be downloaded and added to the
PIP_DOWNLOAD_CACHE
directory. For instance, I now have quite a few Django packages. - This doesn't remove the need for network access, as stated in the pip news, so it's not the answer for creating new
virtualenvs
on the airplane, but it's still great.
这篇关于如何使用pip从本地缓存安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!