47

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='[email protected]',
    install_requires=['cherrypy-wsgiserver'],
    extra_requires=['newrelic'],
    url='https://github.com/od-eon/django-cherrypy',
)

Suggestions?

2
  • 4
    Any one else find the term "optional dependencies" funny? I do. Commented Sep 7, 2017 at 22:30
  • 7
    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. Commented Sep 20, 2017 at 16:27

1 Answer 1

62

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"]
    }
)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @voithos. I should have rtfm. Your recommended link above (peak.telecommunity.com/DevCenter/…) helps a lot!
current setup tools docs on optional dependencies: setuptools.pypa.io/en/latest/userguide/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.