使用 setuptools 时是否有任何理由列出标准库依赖项?

Is there any reason to list standard library dependencies when using setuptools?

我已经进入 Python 包装和分发的困境,我想知道:

Is there ever any reason to provide standard library modules/packages as dependencies to setup() when using setuptools?

还有一个旁注:the only setuptools docs I have found are terrible。还有更好的吗?

谢谢

一句话,没有。依赖项的目的是确保当有人安装您的库时它们可用。由于标准库始终随 python 安装可用,因此您无需包含它们。

如需更加人性化的打包指南,请查看 Hynek 的指南: Sharing Your Labor of Love: PyPI Quick and Dirty

No — 事实上,您应该 永远不要 将标准模块指定为 setup() 要求,因为这些要求仅适用于从 PyPI (or VCS repositories or other package indices). Adding, say, "itertools" to install_requires will mean that your package will fail to install because its dependencies can't be satisfied because there's (currently) no package named "itertools" on PyPI. Some standard modules do share their name with a project on PyPI; in the best case (e.g., argparse 下载包),PyPI 项目与标准模块兼容,仅作为历史 reasons/backwards 兼容性的单独项目存在。最坏的情况……好吧,发挥你的想象力吧。