What "ModuleNotFoundError: No module named" Means

You run your script and Python stops with:

ModuleNotFoundError: No module named 'requests'

It means Python looked through every folder on its import path and couldn't find that module. In most cases the package is installed, just not in the Python environment that's running your code.

Work through the fixes below in order. The first two solve the vast majority of cases.


๐ŸŽฏ Quick Answer (30-Second Read)

  • Most common cause: you installed the package into a different Python than the one running your script.
  • Fix: install with python -m pip install <package>, using the same python you run your code with.
  • Using a virtual environment? Activate it first, then install and run.
  • In VS Code or PyCharm? Select the right interpreter.
  • Still failing? Check the package name (pip install names can differ from import names) and for files that shadow the module.

Fix Checklist (Try in This Order)

  • 1. Install with python -m pip install <package>
  • 2. Activate your virtual environment before installing and running
  • 3. Select the correct interpreter in your editor
  • 4. Check the install name vs the import name
  • 5. Look for a local file or folder with the same name as the module
  • 6. For your own modules: check how you're running the script

Fix 1: Install With the Same Python You Run

Your computer can have several Pythons: system Python, Homebrew, Anaconda, a virtual environment. A bare pip might install into a different one from your python.

# See which Python runs your code
python -c "import sys; print(sys.executable)"

# Install into exactly that Python
python -m pip install requests
Pro tip: make python -m pip a habit instead of plain pip. It guarantees the package goes into the Python you're actually using.

On macOS/Linux you may need python3 -m pip if python isn't set up.


Fix 2: Activate Your Virtual Environment

If your project uses a virtual environment, packages installed inside it are only visible when it's active.

# create (once)
python -m venv .venv

# activate: macOS / Linux
source .venv/bin/activate
# activate: Windows (PowerShell)
.venv\Scripts\Activate.ps1

# then install and run inside it
python -m pip install requests
python app.py

Your terminal prompt usually shows (.venv) when it's active.


Fix 3: Select the Right Interpreter in Your Editor

Code runs fine in the terminal but fails in VS Code (or the other way round)? The editor is using a different interpreter.

  • VS Code: Cmd/Ctrl + Shift + P โ†’ Python: Select Interpreter โ†’ choose your .venv
  • PyCharm: Settings โ†’ Project โ†’ Python Interpreter
  • Jupyter: pick the kernel that matches your environment, or install from inside the notebook with %pip install requests

Fix 4: The Install Name Isn't Always the Import Name

Some packages install under one name and import under another:

You import You pip install
cv2 opencv-python
sklearn scikit-learn
PIL pillow
yaml pyyaml
bs4 beautifulsoup4
dotenv python-dotenv

Running pip install cv2 won't work. Install the right package name.


Fix 5: Check for a File That Shadows the Module

If your project has a file named requests.py, random.py or email.py, Python imports your file instead of the real module. Then the import fails or behaves strangely.

Rename the file (and delete any __pycache__ folder next to it).


Fix 6: Importing Your Own Modules

For your own code (from utils import helper), the error usually depends on where you run from:

project/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ main.py
โ”‚   โ””โ”€โ”€ utils.py
  • Run as a module from the project root: python -m app.main (not python app/main.py)
  • Use package imports inside the package: from app.utils import helper
  • Install your project in editable mode for larger projects: python -m pip install -e .

Still Stuck? Inspect the Import Path

import sys
print(sys.executable)   # which Python is running
for p in sys.path:      # where it looks for modules
    print(p)

If the folder containing the package isn't listed, you're in the wrong environment.


Frequently Asked Questions

I installed the package but still get ModuleNotFoundError. Why?

It was almost certainly installed into a different Python environment from the one running your code. Check python -c "import sys; print(sys.executable)", activate the right virtual environment, and reinstall with python -m pip install so both use the same interpreter.

What's the difference between ModuleNotFoundError and ImportError?

ModuleNotFoundError is a specific kind of ImportError: Python couldn't find the module at all. A plain ImportError usually means the module was found but the name you tried to import from it doesn't exist, or the module failed while loading.

Why does pip say "externally-managed-environment"?

Newer operating systems protect their system Python from direct pip installs. Create a virtual environment (python3 -m venv .venv), activate it, and install there. Or use a tool like pipx for command-line apps.


Conclusion

"No module named โ€ฆ" almost always means a mismatch between where a package was installed and which Python is running. Install with python -m pip, activate your virtual environment, select the same interpreter in your editor, and double-check the package name. Those steps fix nearly every case.


Sources

Last verified: 14 October 2026.


Related reads: How to Use Environment Variables in Next.js ยท Fix Supabase RLS Policy Error ยท CI/CD Explained

I write practical developer fixes and guides. Follow on LinkedIn or X, or invite me to speak.