简体   繁体   中英

How to specify dependencies when creating the setup.py file for a python package

The python doc for "Writing the Setupscript ( http://docs.python.org/2/distutils/setupscript.html ) mentions that dependencies can be specified under section

> 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'.

[...]

Given this rather sparse information without an example I just want to make sure that I do it right. Also, I cannot find this requires parameter in the API description http://docs.python.org/2/distutils/apiref.html#distutils.core.setup

So is it done like this,eg,

setup(name='MyStuff',
      version='1.0',
      requires='os, sys, progressbar',
      [...]

I hope some one can give me a little bit more insight! Thanks!

EDIT:

To address the distutils.core, setuptools controversy, one could simply do

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

Does it make sense?

Ignore distutils . If you want to create a package that specifies dependencies for a tool like pip to go out and find for you, you need to base your setup.py of off setuptools instead.

setuptools dependencies are listed in install_requires , which takes a list:

setup(name='MyStuff',
      version='1.0',
      install_requires=['progressbar'],
      # ...
)

which should be distributions of their own. os and sys are modules included with Python and should not be listed .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM