[Comprehensive Guide] Pip Install Requirements.Txt In Python

If you use pip to manage Python packages (libraries), you can use the requirements.txt configuration file to install the specified packages with the specified version.

The following topics are covered in this article.

  • Using pip, install the following packages: -r specifications.txt
  • How to Create a Requirements.txt Configuration File
  • Pip freeze exports the current environment configuration file.

Install Packages With Pip: -R Requirements.Txt

The command below will install the packages specified in the configuration file.


$ pip install -r requirements.txt

The configuration file can be named whatever you want, but requirements.txt is a common name.

Put the file requirements.txt in the directory where the command will be run. If it’s in a different directory, specify the path as path/to/requirements.txt.

Write Configuration File Requirements.Txt

The following is an example of a configuration file requirements.txt.

###### Requirements without Version Specifiers ######

###### Requirements with Version Specifiers ######
docopt == 0.6.1             # Version Matching. Must be version 0.6.1
keyring >= 4.1.1            # Minimum version 4.1.1
coverage != 3.5             # Version Exclusion. Anything except version 3.5
Mopidy-Dirble ~= 1.1        # Compatible release. Same as >= 1.1, == 1.*

Comments, like Python code, can be written with the # symbol.

You can specify the version using ==, >, >=,, =, and so on. If the version is not specified, the most recent version is installed.

By separating two conditions with a comma, they can be specified. In the following example, a version of 1.0 or later and 2.0 or earlier is installed (= 1.0 = ver = 2.0).

Export current environment configuration file: Pip Freeze

Pip freeze generates a configuration file containing the package and its version installed in the current environment, which can be used with pip install -r.

$ pip freeze

If you use redirect > to output pip freeze to a file, you can use that file to install packages of the same version as the original environment in another environment.

First, output requirements.txt to a file.

$ pip freeze > requirements.txt

This requirement should be copied or moved. txt to a different environment and install it with it.

$ pip install -r requirements.txt

Also read:- [4 Easy Fixes] Error Displaying Widget: Model Not Found On Python


Following this guide will allow you to use the full potential of the requirements.txt configuration file. If something goes wrong, please check your code before posting a query. If you do find the issue to be beyond you then we will be happy to help.

Please share this article with your friends if they are facing the same issue.

Leave a Reply

Your email address will not be published. Required fields are marked *

How To Charge Laptop In Car? [Gadgets Used] What Happens If I Reset My iPhone? Check out iPhone 14 Colors HD Pro All Full Forms Of Computer Subject