ModuleNotFoundError: No module named 'requests'
Python cannot find the requests package in the interpreter environment that is running your code.
What does this error mean?
Python reached an import statement for `requests`, searched the active interpreter's package paths, and did not find an installed module with that name.
Why does this happen?
- The requests package has not been installed.
- The package was installed for a different Python interpreter.
- Your virtual environment is not active.
- The IDE is configured to use a different interpreter than your terminal.
- A local file or folder is interfering with package resolution.
AI explanation
Think of each Python environment as its own toolbox. Your code asked for the `requests` tool, but the toolbox attached to the running Python process does not contain it. Installing the package with that exact interpreter, or switching to the intended environment, resolves the mismatch.
Quick fix
python -m pip install requests python -c "import requests; print(requests.__version__)"
Step-by-step fix
python -m pip install requests
.venv\Scripts\activate python -m pip install -r requirements.txt
Alternative solutions
Windows
py -m pip install requests py app.py
The Python launcher is often the most reliable command on Windows.
macOS / Linux
python3 -m pip install requests python3 app.py
Use python3 when `python` is not mapped to Python 3.
Virtual environment
python -m venv .venv .venv\Scripts\activate python -m pip install requests
On macOS or Linux, activate with `source .venv/bin/activate`.
Conda
conda install requests conda run python app.py
Install into the currently selected Conda environment.
Docker
RUN python -m pip install --no-cache-dir requests
Add the dependency to the image, then rebuild it.
Real example
import requests
response = requests.get("https://api.example.com")# requirements.txt
requests==2.32.5
# app.py
import requests
response = requests.get("https://api.example.com", timeout=10)Frequently asked questions
The terminals are probably using different Python interpreters or virtual environments. Compare the output of `python -c "import sys; print(sys.executable)"` in both.