If you ran:
pip install requirements.txtand 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:
pip install -r requirements.txtThe -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.0redis==5.0.1click==8.1.7will install all three packages with:
pip install -r requirements.txtRecommended Setup
To avoid conflicts and keep things clean, use a virtual environment.
python -m venv .venvsource .venv/bin/activate # On Windows: .venv\Scripts\activatepip install -r requirements.txtTo share your environment with others, generate the file with:
pip freeze > requirements.txtCommon 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:
pip install -r requirements.txt