How to specify dependencies in Python

450 Views Asked by At

I came across a python library which has docs, which start like this:

Quickstart

Include foolib in your requirements.txt file.

AFAIK dependencies should be specified via install_requires in setup.py.

Should I talk the maintainer of the library and create a pull-request for the docs?

2

There are 2 best solutions below

2
On

Both are acceptable. The difference is that specifying something in your install_requires will auto-download / install that package when you install the package using setup.py. Having a requirements.txt makes it easier to see at a glance what the requirements are. I personally prefer seeing libraries with a requirements.txt, since I can install all those requirements with pip into my virtualenv and be able to update them quickly if needed.

0
On

Add your dependencies in a requirements file and then parse this file in the setup.py. This will help you to:

  • Easily install dependencies without installing the entire package through pip
  • Get only one source for your dependencies
  • Get all way to install your package available (pip, easy_install, command line, etc...)