ModuleNotFoundError: No module named ‘x’
Traceback (most recent call last):
File "shelf.py", line 1, in <module>
import pandas_fake
ModuleNotFoundError: No module named 'pandas_fake'What Python is actually saying
You asked me to load a toolkit by that name. I looked everywhere I know to look, and it isn’t there.
Python ships with a set of built-in modules — math, random, datetime, json and others. Everything else has to be installed onto your computer before you can import it.
Cause 1: it was never installed
Most of the well-known libraries — requests, pandas, numpy, matplotlib — do not come with Python. Install from your terminal, not inside your Python file:
pip install requestsThen import requests works.
pip install puts it on your computer. import brings it into this program. You install once; you import in every file that needs it.
Cause 2: the install name and the import name differ
This one is genuinely confusing and nobody warns you:
| You install | You import |
|---|---|
pip install beautifulsoup4 | import bs4 |
pip install Pillow | import PIL |
pip install scikit-learn | import sklearn |
pip install opencv-python | import cv2 |
If pip says the package is already installed and Python still can’t find it, check the library’s own documentation for the import name.
Cause 3: a typo
import requestsSame as a NameError — read the name in the error against what you typed.
Cause 4: installed into a different Python
The awkward one. If you have more than one Python on your machine, or you’re using a virtual environment, pip may have installed into one Python while your editor runs another.
Check they match:
python3 -m pip install requestsUsing python3 -m pip rather than plain pip installs into the Python you’re actually running, which resolves most of these.
In VS Code, check the interpreter shown in the bottom-right corner is the one you installed into.
What to check, in order
- Is it a built-in module, or does it need installing?
- Have you run
pip installfor it? - Does the install name differ from the import name?
- Is the spelling right?
- Try
python3 -m pip installinstead ofpip install
Remember this
This error is rarely about your code. It’s about your setup — which means it’s fixable in the terminal, not the editor, and it usually stays fixed.
The Python Troubleshooting Handbook covers thirty errors like this one — 77 pages, offline, no searching required.