Skip to content
Latchkey

pip install -r: Install from requirements.txt in CI

Install a whole requirements file in one command.

pip install -r reads a requirements file and installs every listed package. It is the standard way CI jobs restore a project’s dependencies.

What it does

Installs all packages listed in a requirements file. The file can pin exact versions, reference other files with -r, include hashes, and point at extra indexes.

Common usage

Terminal
pip install -r requirements.txt
pip install -r requirements.txt -r requirements-dev.txt
pip install --require-hashes -r requirements.lock

Common CI error: file not found

If the working directory is wrong, pip reports the requirements file is missing and the job fails immediately. Reference the file by an explicit path relative to the job’s working directory.

Terminal
# Failure:
# ERROR: Could not open requirements file:
# [Errno 2] No such file or directory: 'requirements.txt'

# Fix: point at the real path
pip install -r ./service/requirements.txt

Options

OptionDoes
-r, --requirement FILEInstall from the given requirements file
--require-hashesRequire a hash for every requirement
-c, --constraint FILEConstrain versions without installing
--no-depsInstall only the listed packages

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →