Easy_install 缓存下载的文件
有没有办法配置 easy_install 以避免在安装失败时再次下载文件?
Is there a way to configure easy_install to avoid having to download the files again when an installation fails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
13年后更新:
easy_install
于2021年1月从Python中删除。Python包管理器是pip
,它缓存下载的包。pip (http://pypi.python.org/pypi/pip/) 是一个easy_install 工具的直接替代品可以做到这一点。
只需运行
easy_install pip
并将环境变量PIP_DOWNLOAD_CACHE
设置为您希望 pip 存储文件的路径。请注意,缓存不适用于从源代码存储库(如 svn/git/hg/bzr)检出的依赖项。
然后使用
pip install
而不是easy_install
Update 13 years later:
easy_install
was removed from Python in January 2021. The python package manager ispip
, it caches downloaded packages.pip (http://pypi.python.org/pypi/pip/) is a drop-in replacement for the easy_install tool and can do that.
Just run
easy_install pip
and set an environment variablePIP_DOWNLOAD_CACHE
to the path you want pip to store the files.Note that the cache won't work with dependencies that checkout from a source code repository (like svn/git/hg/bzr).
Then use
pip install
instead ofeasy_install
这是我使用 pip 的解决方案,甚至可以管理二进制包的安装,并且可以在 Linux 和 Windows 上使用。 根据要求,它将限制从 PyPi 的下载到最低限度,并且作为额外的好处,在 Linux 上,它允许将通常需要编译的软件包的重复安装速度加快到几分之一秒。
设置只需几个步骤,但我认为这是值得做的。
创建 pip 配置文件
创建 pip 配置文件(在 linux 上:~/.pip/pip.conf,在 Windows 上 %HOME%\pip\pip.ini)
我的文件包含以下内容:
填充
cache
dir -自动进行cache
目录每次都会获取从 pypi 下载的数据的缓存版本,pip 尝试从 pypi 获取一些包。 很容易到达那里(不需要特别注意),但请注意,从 pip 的角度来看,这些只是从 PyPi 下载的现金数据,而不是包,所以如果您使用选项--no-索引
,它将不起作用。pip download
填充packages
目录packages
目录是放置真实包文件的地方。 例如,对于我最喜欢的包plac
,我会这样做:plac 包文件将出现在该目录中。 您甚至可以使用
-rrequirements.txt
文件一次对多个包执行此操作。这些包甚至可以与 $ pip install --no-index一起使用。
上重复编译同一个包
防止在Linux
lxml
包需要编译,下载和编译可能需要 45 秒到几分钟。 使用轮子格式,你可以在这里节省很多。安装
wheel
工具(如果您还没有):为
lxml
创建轮子(假设您过去已成功安装lxml
-它需要在系统中安装一些库):这会经过下载、编译,但最终会导致 lxml
whl
文件位于packages
目录中。从那时起
甚至更快
将需要几分之一秒,因为它使用轮格式的包。
从Window setup exe包中准备wheel包
(注意:这甚至可以在Linux机器上准备,没有编译,只是从exe文件重新打包成
whl
。)下载exe形式来自 pypi 的包,例如:
$ wget https://pypi.python.org/packages/2.7/l/lxml/lxml-3.2.3.win32-py2.7.exe#md5=14ab978b7f0a3382719b65a1ca938d33
$ 目录
lxml-3.2.3.win32-py2.7.exe
将其转换为
whl
$ 轮转换 lxml-3.2.3.win32-py2.7.exe
$ 目录
lxml-3.2.3.win32-py2.7.exe
lxml-3.2.3-cp27-none-win32.whl
测试它:
$ pip 安装 lxml
或者
会很快。
请注意,
wheel Convert
可以对 Egg 格式的包执行完全相同的转换。让
easy_install
和setup.py install
重用您的packages
目录easy_install
和$ python setup.py install
似乎不提供下载缓存,但允许使用packages
目录中的包。为此,请编辑这两个工具的配置文件:
在 Linux 上:
$HOME/.pydistutils.cfg
在 Windows 上:
%HOME%\pydistutils.cfg
在我的例子中,我在
/home/javl/.pydistutils.cfg
中有:当 pip 尝试安装包时,此配置甚至可以帮助某些
pip install
调用,声明对其他的。 当它将此任务委托给 setup.py 调用时,如果没有 .pydistutils.cfg 配置,它将从 PyPi 下载文件。不幸的是,在这种情况下不支持轮格式(据我所知)。
Here is my solution using pip, managing even installation of binary packages and usable on both, Linux and Windows. And as requested, it will limit download from PyPi to the minimum, and as extra bonus, on Linux, it allows to speed up repeated installation of packages usually requiring compilation to a fraction of a second.
Setup takes few steps, but I thing, it is worth to do.
Create pip config file
Create pip configuration file (on linux: ~/.pip/pip.conf, on Windows %HOME%\pip\pip.ini)
My one has this content:
Populating
cache
dir - goes automaticallyThe
cache
dir will get cached version of data downloaded from pypi each time, pip attempts to get some package from pypi. It is easy to get it there (no special care needed), but note, that from pip point of view, these are just cashed data downloaded from PyPi, not packages, so in case you use an option--no-index
, it will not work.pip download
to populatepackages
dirThe
packages
dir is place to put real package files to. E.g. for my favorite packageplac
, I would do:and the plac package file would appear in that dir. You may even use
-r requirements.txt
file to do this for multiple packages at once.These packages are used even with
$ pip install --no-index <something>
.Prevent repeated compilation of the same package on Linux
E.g.
lxml
package requires compliation, and download and compile may take from 45 seconds to minutes. Using wheel format, you may save here a lot.Install
wheel
tool, if you do not have it yet:Create the wheel for
lxml
(assuming, you have managed to installlxml
in past - it requires some libs in the system to be installed):This goes over download, compile, but finally results in lxml
whl
file being inpackages
dir.Since then
or even faster
will take fraction of a second, as it uses wheel formatted package.
Prepare wheel package from Window setup exe package
(note: this can be prepared even on Linux machine, there is no compilation, only some repacking from exe file into
whl
.)download the exe form of the package from pypi, e.g:
$ wget https://pypi.python.org/packages/2.7/l/lxml/lxml-3.2.3.win32-py2.7.exe#md5=14ab978b7f0a3382719b65a1ca938d33
$ dir
lxml-3.2.3.win32-py2.7.exe
convert it to
whl
$ wheel convert lxml-3.2.3.win32-py2.7.exe
$ dir
lxml-3.2.3.win32-py2.7.exe
lxml-3.2.3-cp27-none-win32.whl
Test it:
$ pip install lxml
or
shall be very quick.
Note, that
wheel convert
can do exactly the same conversion for egg formatted packages.Let
easy_install
andsetup.py install
reuse yourpackages
direasy_install
and$ python setup.py install
do not seem to offer download cache, but allow to use packages we have in ourpackages
dir.To do so, edit config file for these two tools:
On Linux:
$HOME/.pydistutils.cfg
On Windows:
%HOME%\pydistutils.cfg
In my case I have here in
/home/javl/.pydistutils.cfg
:This config may help even some cases of
pip install
calls, when pip attempts to install a package, declaring dependency on other ones. As it delegates this task tosetup.py
call, without the.pydistutils.cfg
config it would download the file from PyPi.Unfortunately, wheel format is not supported in this case (as far as I am aware of).