Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python setup config install_requires "good practices"

My question here may seem really naive but I never found any clue about it on web resources.

The question is, concerning install_requires argument for setup() function or setup.cfg file, is it a good practice to mention every package used, even python built-in ones such as os for example ?

One can assume that any python environment has those common packages, so is it problematic to explicitly mention them in the setup, making it potentially over-verbose ?

Thanks

like image 550
mrt Avatar asked Dec 17 '22 12:12

mrt


2 Answers

install_requires should include non-standard library requirements, and constraints on their versions (as needed).

For example, this would declare minimal versions for numpy and scipy, but allow any version of scikit-learn:

setup(
  # ...
  install_requires=["numpy>=1.13.3", "scipy>=0.19.1", "scikit-learn"]
)

Packages such as os, sys are part of Python's standard library, so should not be included.

As @sinoroc mentioned, only direct 3rd party dependencies should be declared here. Dependencies-of-your-dependencies are handled automatically. (For example, scikit-learn depends on joblib; when the former is required, the latter will be installed).


I've found it helpful to read other packages and see how their setup.py files are defined.

  • imbalanced-learn
  • pandas
like image 151
Alexander L. Hayes Avatar answered Dec 21 '22 23:12

Alexander L. Hayes


You should list top-level 3rd party dependencies.

  • Don't list packages and modules from Python's standard library.

  • Do list 3rd party dependencies your code directly depends on, i.e. the projects containing:

    • the packages and modules your code imports;
    • the binaries your code directly calls (in subprocesses for example).
  • Don't list dependencies of your dependencies.

like image 37
sinoroc Avatar answered Dec 21 '22 23:12

sinoroc