44

How do I specify optional dependencies in python's setup.py ?

Here's my stab at specifying an optional dependency for an open source library of mine but it doesn't seem to do much.

https://github.com/od-eon/django-cherrypy/blob/master/setup.py

Specifically extra_requires in this snippet:

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',
)

Suggestions?

Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167
  • 4
    Any one else find the term "optional dependencies" funny? I do. – Rob Truxal Sep 07 '17 at 22:30
  • 6
    Funny it may be, but it sure makes a lot of sense. You may design optional features that will be disabled if the lib is not there (eg., an optimization) without breaking anything in the program. More commonly, it's actually very handy to be able to declare **dev** dependencies, like [npm does](https://stackoverflow.com/questions/18875674). – Arnaud P Sep 20 '17 at 16:27

1 Answers1

59

You've got an incorrect keyword. It's extras_require, and it's supposed to be a dict.

setup(
    name="django-cherrypy",
    ...
    extras_require = {
        'mysterious_feature_x':  ["newrelic"]
    }
)
scrutari
  • 1,378
  • 2
  • 17
  • 33
voithos
  • 68,482
  • 12
  • 101
  • 116
  • Thanks @voithos. I should have rtfm. Your recommended link above (http://peak.telecommunity.com/DevCenter/setuptools#declaring-extras-optional-features-with-their-own-dependencies) helps a lot! – Calvin Cheng May 14 '12 at 05:20
  • current setup tools docs on optional dependencies: https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#optional-dependencies – braulio Feb 23 '23 at 11:04