Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependencies auto discovery for Python setuptools?

In packaging a Python application using setuptools, I am populating the install_requires list with all the PyPI dependencies of my application. I find myself manually combing through all my sources to find these. Is this the right way to do it? Or can this list be auto-populated somehow?

like image 802
rishai Avatar asked Dec 18 '25 09:12

rishai


1 Answers

From my point of view install_requires should only list the direct dependencies of your project (not the indirect ones, the dependencies of your dependencies). So it often is a relatively short list, that can probably should be curated by hand, the same way you carefully hand-picked your libraries to begin with.

In common scenarios, using tox in combination with a linting tool such as pylint would let you know if some imports can't be resolved, which most likely means that libraries are missing from install_requires.

In the case you already have lots of dependencies but lost track of which ones and didn't keep install_requires up to date, then I believe a tool such as pipreqs or pigar can help (there are probably other similar tools, but that's the ones I stumbled upon while browsing the following similar questions: 1, 2).

like image 193
sinoroc Avatar answered Dec 19 '25 23:12

sinoroc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!