How to generate requirements.txt in python

A requirements.txt file is essential for managing Python project dependencies. It ensures everyone working on your project has the correct libraries installed for development and deployment.

The simplest way or automatically generate requirements.txt is using piprequs library. It will generate requairements.txt file based on the imports of your project.

First install the library


pip install pipreqs



Navigate to Your Project
In your terminal, open the root directory of your Python project.
( the folder where your python project script located)

And then run this command


pipreqs .


This tool will scan your project’s codebase for import statements and generate a list of required packages.


Later when you need to install your project dependency then just run


pip install -r requirements.txt