How to write requirements.txt in python project

Writing optimised requirements.txt using pipreqs

if you are using pip freeze to generate requirements.txt , it will dump all the dependencies and sub dependencies in requirement.txt.

pip freeze > requirements.txt
pip freeze > requirments.txt

creating the requirements.txt using the pipreqs.

Instaling the pipreqs

pip install pipreqs

for creating the requirements.txt

pipreqs apps/

It scans all the imports in apps folder and create the optimised requirements.txt file in apps directory. Subdepedencies resolved internaly.
output for the above project is :

optimised requirments.txt using pipreqs

for more information:

Resources

https://pypi.org/project/pipreqs/
https://github.com/bndr/pipreqs