ModuleNotFoundError in Python: Why It Happens

You pip-installed it, but Python swears the module doesn't exist. The cause is almost always which Python you're actually running.

BytExplorer 5 min read June 28, 2026

You run your script and Python throws ModuleNotFoundError: No module named 'requests' — but you definitely installed it. This one trips up nearly everyone, and the cause is almost always the same: the Python that ran your script isn't the one you installed the package into.

The real problem: multiple Pythons

A machine often has several Python installations and environments. When you pip install something, it goes into one specific environment. If your script runs under a different Python, that package simply isn't there from its point of view. Same name, different world.

Step 1: Check which Python you're using

which python
python --version

Then check which pip you installed with:

which pip

If python and pip point at different installations, that mismatch is your bug — you installed into one and ran the other.

Step 2: Install into the exact Python you run

The reliable fix is to tie the install to the same interpreter:

python -m pip install requests

Using python -m pip guarantees the package lands in the environment of that python, not some other pip on your PATH.

Step 3: Use a virtual environment

The lasting solution is a per-project virtual environment, so each project has its own isolated packages and there's no ambiguity:

python -m venv venv
source venv/bin/activate
python -m pip install requests

Once a project's virtual environment is activated, python and pip point at the same place by definition — and ModuleNotFoundError from version confusion mostly disappears.

The takeaway

The module isn't really "not found" — it's just not installed in the interpreter you're running. Check which python vs which pip, install with python -m pip, and use a virtual environment per project to stop the confusion at the source.

Put it into practice

Stop reading, start building

This pairs with a hands-on BytExplorer course — do it on your own machine and actually keep the skill.

More in Troubleshooting