How to install Python packages with requirements.txt

In this tutorial, we will discuss how to install python packages with requirements.txt file. It is difficult to install packages individually. So, a better way was to install through a file which is generally named as requirements.txt

               Install Python packages with requirements.txt

In command prompt, change directory to where the requirements.txt file is located.

Make sure that pip is installed in your environment.

Let’s see the command 

pip install -r requirements.txt

After running the following command, packages present in the requirements.txt file will be successfully installed.

 

                Output Python packages to requirements.txt

You can also output all of your packages of the same version to requirements.txt file and use in another environment.

Let’s see the command

pip freeze > requirements.txt

After running the following command you can see all of your packages with version number are outputted in the requirements.txt file. You can use that requirements.txt file in another environment to install those packages.

Also read:

Leave a Reply

Your email address will not be published.