I am packaging a python project and look for the "right" way to specify dpendencies on external files. I am aware of multiple ways to specify dpendencies, but I would like to know how these ways work practically, how they differ, and at which specific time points they are taking effect, respectively.
Known ways to specify dependencies (see here)
- We could specify the dependency in the
install_requires
argument ofsetuptools.setup
- We could use
requirements.txt
- We could use
setup.cfg
My main questions
- What are advantages and disadvantages of the different methods?
- When and in which order are the information in the respective files read? Would e.g. pip first execute
setup.py
and then check therequirements.txt
afterwards? - What happens if I specify a requirement only in one of the ways given above? What happens, if I speciefy different requirements with different ways?
Motivating example
I need to create a package that uses cython
and numpy
. As can be seen e.g. here, cython
(and similarly numpy
, must be imported before setuptools.setup
is called. Hence, setup.py
would raise an ImportError
if the library is not available. How would I make the requirement visible anyway so that the necessary packages are installed before setup.py
is called? Should I move the compilation to a different file that is then called from setup.py
? How would I do that?