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?
Optional dependenciesSetuptools allows you to declare dependencies that are not installed by default. This effectively means that you can create a “variant” of your package with a set of extra functionalities.
The items listed in setup_requires get implicitly installed whenever you execute the setup.py but one of the common ways that the setup.py is executed is via another tool, such as pip , who is already managing dependencies.
The short answer is that requirements. txt is for listing package requirements only. setup.py on the other hand is more like an installation script. If you don't plan on installing the python code, typically you would only need requirements.
package_dir = {'': 'lib'} in your setup script. The keys to this dictionary are package names, and an empty package name stands for the root package. The values are directory names relative to your distribution root.
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"] } )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With