Why use pip install requirements.txt instead of pip install ./?

I’m not very experienced with dependency management in Python but it seems that all of the dependencies in requirements.txt could alternatively be placed in the setup.py file under the install_requires field as follows:

setup(
    ...
    install_requires=['numpy=1.2.3', 'pandas=1.2.3']
    ...
)

Since pip install ./ using a setup.py file also provides lots of additional functionality compared to pip install -r requirements.txt, what is the use for the latter? Would a project ever have a valid reason to use both?

Answer

pip install . installs your custom package with all its dependencies. pip install -r requirements.txt installs only the dependencies.

Leave a Reply

Your email address will not be published. Required fields are marked *