5

I have a program that uses dateutil from the package index. I would like to have setup.py check for for its presence and try to get it using easy_install if it is not there.

The documentation for distutils seems to indicate that this can be done using the requires keyword in setup(), but when I try, it installs on a system without dateutil without giving a warning or installing the required package.

The only thing I could find on google was this blog post about the same issue which did not have any answer either.

Am I using distutils wrong? Do I need to subclass distutils.command.install and do the checking/installing myself?

puffenstuff
  • 205
  • 3
  • 6

2 Answers2

4

Automatic downloading of dependencies is a feature introduced by setuptools which is a third-party add-on to distutils, in particular, the install_requires argument it adds. See the setuptools documentation for more information.

Another option is to use requirements.txt file with pip rather than using easy_install as a package installer. pip has now become the recommended installer; see the Python Packaging User Guide for more information.

Update [2015-01]: The previous version of this answer referred to the distribute fork of setuptools. The distribute fork has since been merged back into a newer active setuptools project. distribute is now dead and should no longer be used. setuptools and pip are now very actively maintained and support Python 3.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • The requires argument in distutils is unusable and unused, you have to use pip requirements files or setuptools’ install_requires argument until PEP 345 is widely used (it makes install_requires officially supported, with a new name: requires-dist; distutils2 supports it). – merwok May 24 '12 at 05:16
  • NB: this comment has become outdated; Distribute and setuptools have merged. Setuptools now has full 3.x support. – Kevin Jan 06 '15 at 21:09
  • @Kevin, thanks for the reminder; a lot has changed since the original answer was written. I've updated the answer to reflect a more current state of the world: the merge back of Distribute and setuptools, the end of distutils2 development, the blessing of `pip` as the official Python package installer, and the new `Python Packaging User Guide`. – Ned Deily Jan 06 '15 at 21:53
0

The argument install_requires in setup function from distutils work for me well, only if I create sdist distributive, like: python setup.py sdist

Nakilon
  • 34,866
  • 14
  • 107
  • 142
al_kash
  • 87
  • 4
  • `install_requires` is **not** an argument of `distutils.core.setup` it is an [extra argument in distribute - setuptools](http://pythonhosted.org/distribute/setuptools.html#new-and-changed-setup-keywords) so you need to use the distribute version of `setup` as @Ned said previously. You can also look at [this answer that describe the state of packaging modules](http://stackoverflow.com/a/14753678/965798) in python. – marcz May 20 '13 at 20:01