23

I would like to release a python module I wrote which depends on several packages. What's the easiest way to make it so these packages are programmatically downloaded just in case they are not available on the system that's being run? Most of these modules should be available by easy_install or pip or something like that. I simply want to avoid having the user install each module separately.

thanks.

  • Most package management systems have a way to specify the dependencies of a package so that dependencies are automatically installed. I don't know how to do it with the setuptools / Python Package Index, but I assume there is a mechanism to similarly specify dependencies. – Michael Aaron Safyan Apr 14 '10 at 04:39

2 Answers2

21

pip uses requirements files, which have a very straightforward format.

For more Python packaging tooling recommendations, see the latest from the Python Packaging Authority (PyPA).

Sam
  • 1,509
  • 3
  • 19
  • 28
gotgenes
  • 38,661
  • 28
  • 100
  • 128
  • @J.F. I would guess Idan Gazit is responsible for the first image; I'm not sure who's responsible for the second. Both are hosted on Amazon S3; the image locations point to their S3 locations, so you can just copy the image locations and use those here and elsewhere. I saw the "Python Comrades" one at Titus Brown's PyCon 2010 talk; the "New Hotness" has been around for maybe a year now. Perhaps some sleuthing on the Python mailing lists can turn up the original source(s). – gotgenes Apr 14 '10 at 06:48
  • Although this is currently the highest voted answer, it doesn't really offer much of a solution (cool graphic though). I currently found [this recent post](https://caremad.io/blog/setup-vs-requirements/) on the subject. Might help others on this search. – bnjmn Aug 11 '13 at 00:18
  • 1
    @fabian789 correct. I have updated the answer. setuptools is the new library of choice. We were always at war with distribute. ;-) – gotgenes Jun 07 '14 at 06:25
  • @bnjmn the hyperlink in your post is no longer active – Hector May 03 '23 at 22:07
  • Thanks @Hector Here's an updated link to [the post](https://caremad.io/posts/2013/07/setup-vs-requirement/) – bnjmn May 09 '23 at 20:29
4

See the setuptools docs on how to declare your dependencies -- this will allow easy_install to find, download and install all of them (and transitive closure thereof) if everything's available in PyPi, or otherwise if you specify the dependencies' URLs.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
  • What do you think about pip? The pip comparisons to setuptools seem very strongly worded... is there really a consensus in the Python community that pip is better? –  Apr 14 '10 at 05:10
  • Also, can pip handle non-PyPi dependencies like setuptools can? –  Apr 14 '10 at 05:11
  • @user, unfortunately I don't have much direct experience with pip, but my impression is that it can do what `easy_install` can, and more. As http://www.b-list.org/weblog/2008/dec/15/pip/ says, "pip does not change your packaging workflow in any way. You just make your package the way you’ve always made it, and then put it up on the Web somewhere (preferably listing it in the Python package index, but you don’t have to if you don’t want to) and people using pip can grab it and install it.". – Alex Martelli Apr 14 '10 at 05:28