How to use the requirements.txt file in Python

In this Answer, we’ll learn to use the requirements.txt file in Python using the PIP. The requirements.txt file is extremely helpful when sharing code via source code management tools like Git, GitHub, GitLab, and Bitbucket. It keeps track of modules, packages, libraries, and frameworks required for the projects. In other words, it contains all of the project requirements.

Create a requirements.txt file

To create the requirements.txt file, we can use the following command:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

A new file will be created in the directory when we run this command. This will list the modules, packages, libraries, and frameworks required for the project.

Note: The requirements.txt file will also include the version number of each module, package, library, and framework. It serves as a list of items to be installed by pip.

Use a requirements.txt file

Once a requirements.txt file is present in the project directory, we can run the following command to install the project requirements.

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

When we run this command, the terminal will list all the modules, packages, libraries, and frameworks installed.

Example

For example, given a requirements.txt file:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Running the pip install -r requirements.txt command will install the project requirements with specified versions as follows:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Note: Most of the time, the requirements.txt file is used to set up a virtual environment. We suggest reading the following Answers to get familiarized with the concepts:

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved