pip install pandas finishes with "Successfully installed pandas-2.x.y". The very next
python -c "import pandas" — or the Run button in VS Code — raises
ModuleNotFoundError: No module named 'pandas'.
The most-reported beginner failure in Python, and a regular at real workplaces too.
Typical setups: a project with a .venv that is activated in one terminal but not
another; VS Code pointed at a different interpreter than the terminal; or a machine
with several Pythons (system, python.org, Store, Anaconda) where pip belongs to one
and python to another. Linked module: 0.1, exercise 3 reproduces this on purpose.
"Successfully installed" and "No module named" are both true — they happened in two
different Pythons. pip installs into the interpreter it belongs to; the import ran in
a different one. Prove it instead of guessing: pip --version prints the path of the
Python it serves, and python -c "import sys; print(sys.executable)" prints the
interpreter actually running. If those two paths differ, you have found the bug. In
VS Code, also check the interpreter shown in the status bar — a third party that can
disagree with both.
Pick the environment you meant to use, then force agreement. Activate the project's
virtual environment and rerun both the install and the import there. When activation
is not possible (scripts, cron, CI), bypass ambiguity by full path:
.venv/bin/python -m pip install pandas then .venv/bin/python your_script.py
(Windows: .venv\Scripts\python). The python -m pip form is the professional habit —
it guarantees pip and python are the same interpreter by construction. In VS Code, run
"Python: Select Interpreter" and choose the .venv entry so the editor joins the same
agreement.
One project, one virtual environment, always activated before any pip command. Prefer
python -m pip install … over bare pip install …. After every install, verify with
one line: python -c "import <package>; print(<package>.__version__)". When a teammate
reports this error, ask for the two proof commands' outputs — not a screenshot of the
successful install.
Q: "pip says a package installed successfully but the import fails. What happened?"
Strong answer: state plainly that two interpreters were involved, name the two proof
commands (pip --version, sys.executable), give the python -m pip fix, and note
the VS Code interpreter setting as the third place that must agree. Bonus points for
saying you would reproduce it deliberately — it shows the debugging mindset, not luck.