SuperCow
SuperCow

Reputation: 1613

What does " -r " do in pip install -r requirements.txt

I looked up how to install multiple packages from a requirements document using pip. The answers were mostly:

 pip install -r requirements.txt

What does the -r do though? I can't find an answer for this and it isn't listed when I run pip help.

Upvotes: 65

Views: 65136

Answers (5)

May, 2022 Update:

If you run this command below without "-r":

pip install requirements.txt

You will get this error below:

ERROR: Could not find a version that satisfies the requirement requirements.txt (from versions: none) HINT: You are attempting to install a package literally named "requirements.txt" (which cannot exist). Consider using the '-r' flag to install the packages listed in requirements.txt ERROR: No matching distribution found for requirements.txt

Because "pip" tries to install the package "requirements.txt" instead of installing the packages listed in "requirements.txt". Of cource, the package "requirements.txt" doesn't exist in PyPI while for example, the packages "django" and "pillow" exist in PyPI:

pip install django
pip install pillow

So, to install the packages listed in "requirements.txt", you must need "-r";

pip install -r requirements.txt

You can check what "-r" means by running the command below:

pip install --help

-r, --requirement Install from the given requirements file. This option can be used multiple times.

Upvotes: 8

OlavRG
OlavRG

Reputation: 832

pip install requirements.txt

Above statement looks for a python package named requirements.txt. No such package exists. Your intention is that pip install opens the txt and reads the packages from there. The -r allows pip install to open requirements.txt and install the packages inside of it instead.

Upvotes: 4

Tanguy
Tanguy

Reputation: 3314

In your case pip install -r requirements.txt will install the libraries listed in your requirements.txt file.

Upvotes: 5

Alvaro Silvino
Alvaro Silvino

Reputation: 9753

-r will search for requirement file.

pip install --help

will help you !!

Upvotes: 14

alecxe
alecxe

Reputation: 474141

Instead of pip --help, look into pip install --help:

-r, --requirement Install from the given requirements file. This option can be used multiple times.

Also see these documentation paragraphs:

Upvotes: 57

Related Questions