Easy_install 缓存下载的文件

发布于 2024-07-13 05:42:44 字数 44 浏览 4 评论 0原文

有没有办法配置 easy_install 以避免在安装失败时再次下载文件?

Is there a way to configure easy_install to avoid having to download the files again when an installation fails?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撧情箌佬 2024-07-20 05:42:44

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 is pip, 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 variable PIP_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 of easy_install

森林散布 2024-07-20 05:42:44

这是我使用 pip 的解决方案,甚至可以管理二进制包的安装,并且可以在 Linux 和 Windows 上使用。 根据要求,它将限制从 PyPi 的下载到最低限度,并且作为额外的好处,在 Linux 上,它允许将通常需要编译的软件包的重复安装速度加快到几分之一秒。

设置只需几个步骤,但我认为这是值得做的。

创建 pip 配置文件

创建 pip 配置文件(在 linux 上:~/.pip/pip.conf,在 Windows 上 %HOME%\pip\pip.ini)

我的文件包含以下内容:

[global]
download-cache = /home/javl/.pip/cache
find-links = /home/javl/.pip/packages

[install]
use-wheel = yes

[wheel]
wheel-dir = /home/javl/.pip/packages

填充 cache dir -自动进行

cache 目录每次都会获取从 pypi 下载的数据的缓存版本,pip 尝试从 pypi 获取一些包。 很容易到达那里(不需要特别注意),但请注意,从 pip 的角度来看,这些只是从 PyPi 下载的现金数据,而不是包,所以如果您使用选项 --no-索引,它将不起作用。

pip download 填充 packages 目录

packages 目录是放置真实包文件的地方。 例如,对于我最喜欢的包 plac,我会这样做:

$ pip download --dest ~/.pip/packages plac

plac 包文件将出现在该目录中。 您甚至可以使用 -rrequirements.txt 文件一次对多个包执行此操作。

这些包甚至可以与 $ pip install --no-index一起使用。

上重复编译同一个包

防止在Linux lxml 包需要编译,下载和编译可能需要 45 秒到几分钟。 使用轮子格式,你可以在这里节省很多。

安装 wheel 工具(如果您还没有):

$ pip install wheel

lxml 创建轮子(假设您过去已成功安装 lxml -它需要在系统中安装一些库):

$ pip wheel lxml

这会经过下载、编译,但最终会导致 lxml whl 文件位于 packages 目录中。

从那时起

$ pip install lxml

甚至更快

$ pip install --no-index lxml

将需要几分之一秒,因为它使用轮格式的包。

从Window setup exe包中准备wheel包

(注意:这甚至可以在Linux机器上准备,没有编译,只是从exe文件重新打包成whl。)

  1. 下载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

  2. 将其转换为 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

  3. 测试它:

    $ pip 安装 lxml

或者

$ pip install --no-index lxml

会很快。

请注意,wheel Convert 可以对 Egg 格式的包执行完全相同的转换。

easy_installsetup.py install 重用您的 packages 目录

easy_install$ python setup.py install 似乎不提供下载缓存,但允许使用 packages 目录中的包。

为此,请编辑这两个工具的配置文件:

在 Linux 上:$HOME/.pydistutils.cfg

在 Windows 上:%HOME%\pydistutils.cfg

在我的例子中,我在 /home/javl/.pydistutils.cfg 中有:

[easy_install]
find_links = /home/javl/.pip/packages

当 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:

[global]
download-cache = /home/javl/.pip/cache
find-links = /home/javl/.pip/packages

[install]
use-wheel = yes

[wheel]
wheel-dir = /home/javl/.pip/packages

Populating cache dir - goes automatically

The 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 populate packages dir

The packages dir is place to put real package files to. E.g. for my favorite package plac, I would do:

$ pip download --dest ~/.pip/packages plac

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:

$ pip install wheel

Create the wheel for lxml (assuming, you have managed to install lxml in past - it requires some libs in the system to be installed):

$ pip wheel lxml

This goes over download, compile, but finally results in lxml whl file being in packages dir.

Since then

$ pip install lxml

or even faster

$ pip install --no-index lxml

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.)

  1. 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

  2. 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

  3. Test it:

    $ pip install lxml

or

$ pip install --no-index lxml

shall be very quick.

Note, that wheel convert can do exactly the same conversion for egg formatted packages.

Let easy_install and setup.py install reuse your packages dir

easy_install and $ python setup.py install do not seem to offer download cache, but allow to use packages we have in our packages 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:

[easy_install]
find_links = /home/javl/.pip/packages

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 to setup.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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文