gpt4 book ai didi

python - 在为 python 包创建 setup.py 文件时如何指定依赖项

转载 作者:太空狗 更新时间:2023-10-29 16:56:02 25 4
gpt4 key购买 nike

“编写安装脚本 (http://docs.python.org/2/distutils/setupscript.html)”的 python 文档提到可以在部分下指定依赖项

> 2.4. Relationships between Distributions and Packages

[...] These relationships can be specified using keyword arguments to the distutils.core.setup() function.

Dependencies on other Python modules and packages can be specified by supplying the requires keyword argument to setup(). The value must be a list of strings. Each string specifies a package that is required, and optionally what versions are sufficient.

To specify that any version of a module or package is required, the string should consist entirely of the module or package name. Examples include 'mymodule' and 'xml.parsers.expat'.

[...]

鉴于这些信息相当稀疏且没有示例,我只想确保我做对了。另外,我在 API 描述中找不到这个 requires 参数 http://docs.python.org/2/distutils/apiref.html#distutils.core.setup

那么是不是这样做的,例如,

setup(name='MyStuff',
version='1.0',
requires='os, sys, progressbar',
[...]

我希望有人能给我更多的见解!谢谢!

编辑:

要解决 distutils.core、setuptools 争议,可以简单地做

try:
from setuptools import setup
except ImportError:
from distutils.core import setup

有道理吗?

最佳答案

忽略 distutils。如果你想创建一个包来为像 pip 这样的工具指定依赖项来为你寻找,你需要将你的 setup.py 设置为 off setuptools相反。

setuptools 依赖项在 install_requires 中列出,它需要一个列表:

setup(name='MyStuff',
version='1.0',
install_requires=['progressbar'],
# ...
)

这应该是他们自己的发行版。 ossys 是 Python 包含的模块,不应列出

关于python - 在为 python 包创建 setup.py 文件时如何指定依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17727398/

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