Deploy
Overview
Fixing the pip install requirements.txt Error

Fixing the pip install requirements.txt Error

November 6, 2024
1 min read

If you ran:

Terminal window
pip install requirements.txt

and got an error, the reason is simple.

Pip is trying to find a package named requirements.txt on PyPI, but that package does not exist.

The correct command is:

Terminal window
pip install -r requirements.txt

The -r flag tells pip to install packages listed inside the file instead of treating the file name as a package.

What Happens Without -r

When you type pip install requirements.txt, pip assumes requirements.txt is a package name.

With -r, pip reads each line of the file as a dependency to install.

So this file:

flask==3.0.0
redis==5.0.1
click==8.1.7

will install all three packages with:

Terminal window
pip install -r requirements.txt

To avoid conflicts and keep things clean, use a virtual environment.

Terminal window
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txt

To share your environment with others, generate the file with:

Terminal window
pip freeze > requirements.txt

Common Issues

  • Running pip outside the project directory
  • Using pip instead of pip3 on systems with multiple Python versions
  • Missing or misnamed requirements.txt file
  • Forgetting to activate the virtual environment

Summary

pip install requirements.txt fails because pip expects a package name, not a file.

Always use the -r flag to tell pip to read dependencies from the file:

Terminal window
pip install -r requirements.txt