Requirements.txt in Python

This article teaches how to create requirements.txt in python for your project.

What is requirements.txt in python?

Requirements.txt is a simple text file which enlists all the modules necessary to run the project without any error.

The packages that must be installed before running the project are all listed in requirements.txt file.

What is the purpose of creating requirements.txt file?

Just listing the packages is not purpose of creating requirements.txt file, installing all the required packages in just one command is the main purpose this requirements.txt file.

How to create requirements.txt file in python?

For python 2, 
  pip freeze > requirements.txt
For python 3,
  pip3 freeze > requirements.txt

Execute the above command according to your python version and a file named requirements.txt will be created. Before executing the command be sure to be in the project directory.

How to install or use packages from requirements.txt file in python?

Now that you have created requirements.txt, to install the packages listed inside the file simply use the command below according to your python version

For python 2,
  pip install -r requirements.txt
For python 3,
  pip3 install -r requirements.txt

Comments