在pypi的Python setup.py中指定可选依赖项。

44
我该如何在Python的setup.py中指定可选依赖项?
以下是我为我的开源库指定可选依赖项的尝试,但好像没有什么作用。
特别是这个片段中的extra_requireshttps://github.com/od-eon/django-cherrypy/blob/master/setup.py
setup(
    name='django-cherrypy',
    version='0.1',
    packages=packages,
    license='LICENSE',
    description='cherrypy, running under django',
    long_description=open('README.md').read(),
    author='Calvin Cheng',
    author_email='calvin@calvinx.com',
    install_requires=['cherrypy-wsgiserver'],
    extra_requires=['newrelic'],
    url='https://github.com/od-eon/django-cherrypy',
)

有建议吗?


4
还有其他人觉得“可选依赖项”这个术语很有趣吗?我觉得挺有趣的。 - Rob Truxal
6
虽然可能有趣,但它确实很有道理。您可以设计可选功能,如果该库不存在,则将其禁用(例如优化),而不会破坏程序中的任何内容。更常见的是,能够声明开发依赖项非常方便,就像npm一样。 - Arnaud P
1个回答

59

你使用了错误的关键词,应该使用 extras_require,并且它应该是一个字典。

setup(
    name="django-cherrypy",
    ...
    extras_require = {
        'mysterious_feature_x':  ["newrelic"]
    }
)

谢谢@voithos。我应该先看文档。你上面推荐的链接(http://peak.telecommunity.com/DevCenter/setuptools#declaring-extras-optional-features-with-their-own-dependencies)帮了我很多! - Calvin Cheng
当前设置工具文档中的可选依赖项:https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#optional-dependencies - braulio

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接