How can I define multiple requirement files?

Question:

How can I do define multiple requirements files in my requirements.txt file.

-r base.txt
-r test.txt

The current behavior is that pip only installs packages from test.txt. I’d expect pip to install packages found in both base.txt and test.txt. I could have sworn I’ve seen someone do this in the past, but I can’t find any examples.

Asked By: self.

||

Answers:

pip accepts multiple -r arguments:

pip install -r reqs1.txt -r reqs2.txt

The help for pip install says:

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

Answered By: snakecharmerb

You can have one file “include” the other; for example, if you put this in file2.txt:

-r file1.txt
Django
Flask
etc.

Then when you do pip install -r file2.txt, it will also install things from file1.txt.

I often use this strategy to have a “base” requirements file, and then only specify those things that are required at each stage (development, testing, staging, production, etc.)

Answered By: Burhan Khalid

I have many requirements in different directories and solve this problem as:

sudo find . -name "requirement*" -type f -exec pip3 install -r '{}' ';'
Answered By: storenth
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.