3

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?

jsstuball
  • 4,104
  • 7
  • 33
  • 63

2 Answers2

5

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

Alec
  • 8,529
  • 8
  • 37
  • 63
  • Are there times when one would want to only install the dependencies and not the package itself? – jsstuball Mar 23 '19 at 06:53
  • Sure. You might have already installed the package, but not installed its dependencies. If you're working in a virtual environment or across many systems it can be an issue. – Alec Mar 23 '19 at 06:56
0

You could also add -e . to your requirements.txt and install your package with pip install -r requirements.txt

Chiel
  • 1,865
  • 1
  • 11
  • 24