Search code examples
pythonsetup.pyrequirements.txt

requirements.txt vs setup.py


I started working with Python. I've added requirements.txt and setup.py to my project. But, I am still confused about the purpose of both files. I have read that setup.py is designed for redistributable things and that requirements.txt is designed for non-redistributable things. But I am not certain this is accurate.

How are those two files truly intended to be used?


Solution

  • 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.