9

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

1
  • Thanks for all the answers, it gets much clear now ! Commented Dec 17, 2020 at 8:21

3 Answers 3

10

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).
  • A list of standard library packages are listed here: https://docs.python.org/3/library/

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

Sign up to request clarification or add additional context in comments.

Comments

5

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.

Comments

4

install_requires should mention only packages that don't come prepackaged with the standard library.

If you're afraid some package might not be included due to Python versioning, you can specify that your packages requires a python version bigger or equal to X.

Note: That packaging python packages is a notoriously hairy thing.

I'd recommend you take a look at pyproject.toml, these can be pip installed like any normal package and are used by some of the more modern tools like poetry

1 Comment

PEP 631 is not relevant here as of today. It is not implemented yet by any tool that I know of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.