How to Create a Requirements.txt File for a Django Project


In this article, we show how to create a requirements.txt file for a Django project.

A requirements.txt file is a file that lists all of the modules needed for the Django project to work. These are all the modules, such as matplotlib, django-allauth, scipy, numpy, etc. that the Django project needs to work.

A requirements.txt file simply lists all of these modules.

So how can we create a requirements.txt file?

Well, before we do this, you may know that typing in, pip freeze, into your command terminal lists all of the modules that you have installed for your project.

This is shown below.

So the above line lists all of the modules you have installed for a project.

Now if we take this a step further, we can list all of the modules with pip freeze and have a requirements.txt file created this listing copied to the text file.

This is done with the following code shown below.

So now we have a requirements.txt file created that lists all of the modules that you installed for the project.

When going live with a Django project, you want this requirements.txt file in the root directory of the project (where is).

Again, this requirements.txt file is needed when choosing certain methods to deploy a Django website.

Related Resources

How to Randomly Select From or Shuffle a List in Python

HTML Comment Box is loading comments...