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

标签 python package setup.py

“编写安装脚本 (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/

相关文章:

python - 如何安装 python 模块

python - 如何测试变量的类型?

python - pip 安装。仅创建 dist-info 而不是包

python - 根据其他列的值为 Pandas Dataframe 创建列

android - 如果使用 android 工具来重命名包名称而不会出现任何错误/冲突

centos - 尝试在加载 libjpeg.so.62 时运行 wkhtml 时出错 : cannot open shared object file

R 创建带有 R CMD 检查的引用手册

python - 何时在 setup.py 中使用 pip 需求文件与 install_requires?

python setup.py : how to set the path for the generated . 所以

python - 将 16 位值拆分为 12+4 python 结构