gpt4 book ai didi

python - setup.py 中的 extras_require() 和 install_requires() 之间的区别?

转载 作者:IT老高 更新时间:2023-10-28 20:22:14 37 4
gpt4 key购买 nike

我试图了解 setup.py 中 extras_require()install_requires() 之间的区别,但无法理解。两者都是用来安装Python依赖的,但是它们有什么区别呢?

最佳答案

根据setuptools documentation ,

extras_require
A dictionary mapping names of “extras” (optional features of your project) to strings or lists of strings specifying what other distributions must be installed to support those features.

install_requires
A string or list of strings specifying what other distributions need to be installed when this one is.

关于 Declaring “Extras” (optional features with their own dependencies) 的部分对此进行了详细说明:

Sometimes a project has “recommended” dependencies, that are not required for all uses of the project. For example, a project might offer optional PDF output if ReportLab is installed, and reStructuredText support if docutils is installed. These optional features are called “extras”, and setuptools allows you to define their requirements as well. In this way, other projects that require these optional features can force the additional requirements to be installed, by naming the desired extras in their install_requires.

最大的不同是extras_require中的需求只是按需安装:

These requirements will not be automatically installed unless another package depends on them (directly or indirectly) by including the desired “extras” in square brackets after the associated project name. (Or if the extras were listed in a requirement spec on the EasyInstall command line.)

总结一下:

  • 如果依赖项对于运行您的项目是必需,请将其放入install_requires。它们将始终安装。
  • 如果您的项目具有添加依赖项的可选功能,请将这些依赖项放在 extras_require 中。这些依赖项将不会安装,除非用户或其他软件包要求该功能。

关于python - setup.py 中的 extras_require() 和 install_requires() 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41268863/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com