What This Error Means
pip was asked to install from a requirements file path that does not exist (wrong filename, wrong directory, or missing checkout).
How to Fix It
- Run the command from the directory containing the file, or pass the correct relative/absolute path to
-r. - Fix typos (
requirements.txtvsrequirement.txt). - If the file truly doesn't exist, generate one only if appropriate:
python -m pip freeze > requirements.txt(note: this captures your current environment, which may not match a project).
Why It Happens
- You ran the command from a directory that doesn't contain the file.
- The file is named differently (common typo:
requirement.txt). - The repository checkout is incomplete or the file was not committed.
How to Verify
- Run
python -m pip install -r requirements.txtand confirm pip begins installing packages. - If you're using a custom path, confirm it resolves correctly:
python -c 'import pathlib; print(pathlib.Path("path/to/requirements.txt").resolve())'.
Manual file path checks
- List files in your current directory:
ls -la. - Confirm the filename is exactly
requirements.txt(plural is the common convention). - If you are in CI, confirm the repo was checked out and your job runs from the right working directory.
Common CLI Output
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirement.txt' How pip reads requirements files
- When you run
pip install -r requirements.txt, pip opens the file path and parses each requirement line. - If the path is wrong or the file isn't present in the current working directory, pip fails before it can install anything.
Prevention Tips
- Keep
requirements.txtin a predictable location and document it. - In CI, set the working directory explicitly before running pip.
- Use lock files or pinned requirements for reproducibility where possible.
Where This Can Be Triggered
github.com/pypa/pip/blob/25.3/src/pip/_internal/req/req_file.py
pip reads requirements files from a URL or a local path, if opening the path fails, it raises an InstallationError with "Could not open requirements file: ...". - GitHub
# Assume this is a bare path.
try:
with open(url, "rb") as f:
raw_content = f.read()
except OSError as exc:
raise InstallationError(f"Could not open requirements file: {exc}")