If you’ve been learning or working with Python, you’ve probably seen this error before:
ModuleNotFoundError: No module named ‘requests’
It’s one of the most common errors developers run into when dealing with third-party libraries. The good news is that it’s easy to fix once you understand what’s going on.
In this post, we’ll break down what this error means, why it happens, and how to solve it step-by-step — whether you’re working in a virtual environment, using Jupyter Notebook, or running code on a server.
What the Error Means
When Python throws a ModuleNotFoundError, it’s telling you that the module or library you’re trying to use hasn’t been installed or isn’t accessible in your current environment.
The message No module named ‘requests’ means Python looked for a module named requests (a popular HTTP library for sending API requests) but couldn’t find it in the list of installed packages.
The requests library doesn’t come built into Python by default — you need to install it manually before using it.
For example, if you run this code:
import requests
and Python responds with that error, it means your environment doesn’t have the requests library installed.
Why This Error Happens
There are a few common reasons why this error shows up:
- The requests module isn’t installed at all.
This is the most straightforward cause — you simply haven’t installed it yet. - You installed it in a different environment.
If you’re using virtual environments (like venv, conda, or poetry), you might have installed the package in one environment but are running your code in another. - Your Python version or path is mismatched.
Sometimes, especially when multiple Python versions are installed, the system installs packages for one version (e.g., Python 3.10) but runs the script using another (e.g., Python 3.11). - Using Jupyter or IPython with a different interpreter.
If you’re using Jupyter Notebook or an IDE like VS Code, it might be running a kernel that doesn’t have the requests package installed.
Understanding which of these applies to you helps solve the problem faster.
Step-by-Step Fix
1. Check if the Requests Library Is Installed
Open your terminal or command prompt and run:
pip show requests
If it returns details about the package (like version and location), it’s already installed — but possibly in a different environment.
If you see something like:
WARNING: Package(s) not found: requests
then it’s not installed, and you need to install it.
2. Install the Requests Module
Use pip, Python’s package manager, to install it:
pip install requests
If you’re using Python 3 and your system defaults to Python 2 when running pip, try:
pip3 install requests
Once installation completes, verify it:
pip show requests
If you see details about the library, it’s successfully installed.
3. Make Sure You’re Using the Correct Python Environment
If you still get the error after installing, check which Python version you’re using to run your script:
python –version
and also check which pip version you used:
pip –version
You’ll often find something like this:
pip 23.2.1 from /usr/local/lib/python3.10/site-packages (python 3.10)
and
Python 3.11.0
If the versions don’t match, that’s your problem — you installed requests for Python 3.10, but you’re running your code with Python 3.11.
To fix this, install the module specifically for the version you’re using:
python3.11 -m pip install requests
4. Fixing the Error in a Virtual Environment
If you’re working inside a virtual environment (venv), make sure it’s activated before installing packages.
For example:
On Windows:
venv\Scripts\activate
pip install requests
On macOS/Linux:
source venv/bin/activate
pip install requests
Once activated, the package will be installed inside that environment and should work immediately when you import it.
5. Installing Requests in Jupyter Notebook
If you’re using Jupyter Notebook and get the error, install the package directly from within a notebook cell:
!pip install requests
Then restart the kernel to make sure the new package is loaded properly.
Alternatively, you can check which Python environment your notebook kernel is using by running:
import sys
print(sys.executable)
Then, install the package into that same environment.
6. For Anaconda Users
If you’re using Anaconda or Miniconda, install requests using conda:
conda install requests
This ensures compatibility with other packages managed by conda.
Common Mistakes to Avoid
- Using pip outside the right environment.
Always confirm your terminal or IDE is pointing to the same Python environment where you’re running code. - Using sudo pip install unnecessarily.
Avoid installing Python packages globally unless you have a good reason — it’s better to use virtual environments. - Ignoring pip warnings.
If pip warns about path issues or outdated versions, pay attention — it often helps identify environment conflicts early. - Misspelling the module name.
Python is case-sensitive. Typing import request (singular) will also cause a similar error.
Testing Your Installation
Once installed, test if it works:
import requests
response = requests.get(“https://www.google.com”)
print(response.status_code)
If this runs without error and returns 200, the module is installed correctly.
Keeping Your Python Environment Clean
To avoid these types of issues in the future, it’s good practice to:
- Use a requirements.txt file to track your project’s dependencies.
- Create separate virtual environments for each project.
Regularly update your packages with:
pip install –upgrade pip
pip install –upgrade requests
This keeps your environment organized and minimizes dependency conflicts.
Final Thoughts
The “ModuleNotFoundError: No module named ‘requests’” error is one of those simple but frustrating Python issues that almost everyone encounters at some point. The root cause is usually either a missing installation or a mismatch between environments.
Once you know how to check where and how packages are installed, you’ll fix this error quickly and avoid it in the future.
Mastering environment management is a big part of becoming confident with Python development — and solving this kind of issue is a great step in that direction.

