requirements.txt vs setup.py

requirements.txt:

This helps you to set up your development environment.

Programs like pip can be used to install all packages listed in the file in one fell swoop. After that you can start developing your python script. Especially useful if you plan to have others contribute to the development or use virtual environments.
This is how you use it:

pip install -r requirements.txt

It can be produced easily by pip itself:

pip freeze > requirements.txt

pip automatically tries to only add packages that are not installed by default, so the produced file is pretty minimal.


setup.py:

This helps you to create packages that you can redistribute.

The setup.py script is meant to install your package on the end user’s system, not to prepare the development environment as pip install -r requirements.txt does. See this answer for more details on setup.py.


The dependencies of your project are listed in both files.

Leave a Comment