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

痴心易碎 提交于 2020-01-19 09:45:13

问题


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,e.g.,

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?


回答1:


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.



来源:https://stackoverflow.com/questions/17727398/how-to-specify-dependencies-when-creating-the-setup-py-file-for-a-python-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!