
Quick answer: You ran pip install something, pip said Requirement already satisfied, and Python still answers ModuleNotFoundError: No module named 'something'. The cause is almost never a broken installation of the package. It is that pip and python in your terminal belong to two different environments. The fix in one line: install with the interpreter you actually run — python -m pip install something — and never rely on bare pip again.
Problem-solving article in the Python series. It works for the classic trio: ModuleNotFoundError, its older sibling ImportError, and the popular complaint that a package installed with pip still cannot be imported.
Table of Contents
What the error really means
When Python hits import module, it does not search your whole disk. It searches a finite list of directories called sys.path, plus the package folder of the interpreter that is executing that import. If the module is not on that list, the interpreter raises ModuleNotFoundError.
So the error is literally a statement about one very specific interpreter: the environment behind this exact python process does not contain this module. It says nothing about any other Python installation on your machine, which is exactly why it can be true in one terminal and false in another.
import sys
print(sys.executable) # which python is actually running this code?
print('\n'.join(sys.path)) # which folders will it look in?
# ModuleNotFoundError follows directly from what you see hereRun those two lines inside the failing script. Nine times out of ten the path printed does not contain the site-packages folder you were thinking of.
The one root cause to memorize
pip installed the package into a different environment than the python that runs your code.
There are several ways this happens, and every one of them produces the same confusing symptom:
- You have two or more Python versions (for example a system Python next to an installer Python), and the terminal resolves
pipto one while your script runs under the other. - A virtual environment exists but was never activated in the terminal where you installed, or was later closed, so pip fell back to a global environment.
- An IDE, a running server, or a notebook keeps its own interpreter that was never restarted after you installed the package.
- The package went into an administrator path you cannot read, or into a container you have since left.
- Your command
pipis simply a leftoverpip.exeon PATH pointing at an old Python.
The detailed fix below resolves every one of these with the same three checks.
Step 1: identify the interpreter you are running
In the same terminal where the import fails, ask Python to identify itself. This must be the exact same command word you use to run the script (python, python3, or py -3), not a nearby alias.
python -c "import sys; print(sys.executable)"
python --versionOn Windows note whether the path mentions AppData\Local\Programs\Python, Program Files, WindowsApps or some venv folder. On macOS and Linux note whether it mentions a system path such as /usr/lib/python, Homebrew, conda, or a venv. If this output surprises you, everything else follows from it: this interpreter — and only this one — is your target.
Step 2: identify the environment your pip belongs to
Do the same diagnostic for pip before touching anything:
pip --version # shows the python folder this pip installs into
python -m pip --version # shows the pip bound to the python you runWhen the two lines print different python folders, you have caught the bug in the act: your pip and your python are simply not the same team. python -m pip install is then guaranteed to be the fix, because python -m forces the module to run through the very interpreter you named.
Step 3: install with the interpreter (the golden rule)
Replace every bare pip install with the explicit form and the mystery disappears:
# Windows (any shell)
python -m pip install requests
# macOS / Linux, where python may be python3
python3 -m pip install requests
# Windows py launcher, if you juggle many versions
py -3.12 -m pip install requestsThis works because -m means run the module in the package of this exact interpreter. The package cannot land anywhere except in the environment of the python you will then run to import it.
Step 4: use a virtual environment so this never happens again
The durable fix is to stop fighting over the global environment. Create one virtual environment per project, activate it in every terminal and editor session that touches the project, and install only there:
# one-time, in the project folder
python -m venv .venv
# activate it
.venv\Scripts\activate # Windows (PowerShell: .venv\Scripts\Activate.ps1)
source .venv/bin/activate # macOS / Linux
# then the terminal prompt usually shows the venv name
python -m pip install requestsWith an activated venv, a bare pip is safe again because the PATH now resolves pip to the venv’s own command. Keep the interpreter check from Step 1 in your habits; the printed path should end in .venv\Scripts\python.exe or .venv/bin/python.
Record the environment so teammates (and future you) can rebuild it anywhere:
python -m pip freeze > requirements.txtStep 5: teach your editor about the environment
VS Code runs code with whatever interpreter is selected bottom-left (or in the command palette under Python: Select Interpreter), and it may not be the one your terminal uses. Select the same .venv interpreter, open a fresh integrated terminal, and confirm the paths match:
python -c "import sys; print(sys.executable)"If VS Code still fails import while the terminal works, the usual culprits are a stale file explorer state (reload the window) or a notebook kernel that was never restarted after installing the package.
Jupyter: each notebook kernel is pinned to one interpreter, so pip in a general terminal may install elsewhere. Install from inside the notebook so the install follows the kernel:
import sys
!{sys.executable} -m pip install requestsThe import name is not the package name
Some of the most-searched cases are not environment problems at all. Pip knows the package under its distribution name, but the code imports a different top-level module name. This mismatch is normal and documented per package:
| You install with pip now | You import in code then |
|---|---|
| beautifulsoup4 | bs4 |
| PyYAML | yaml |
| Pillow | PIL |
| python-dateutil | dateutil |
| opencv-python | cv2 |
| scikit-learn | sklearn |
If a plain diagnostic shows the environment is right but the import still fails, verify the import name from the package page, then finally test both names:
import importlib.util
print(importlib.util.find_spec('bs4')) # None means not in this env; otherwise a path existsOddball causes that waste hours
- A local file shadows the module. A file you named
requests.pyin your own project makesimport requestsimport your file. Python checks the current file directory first. Rename the clashing file (and its.pycin any__pycache__folder). - The package needs system components. Some distributions ship compiled extensions and can fail to expose a module until extra system libraries exist. The pip error text will describe the missing component rather than the module.
- You installed as admin/user and run as the other. Elevated terminals can install into a location your normal user never imports from. Install into a venv created under your normal user to sidestep the mess entirely.
- You left the container. Inside Docker, each build stage and container has its own environment; installing on your host does nothing for the image. Install inside the same container or bake
python -m pip installinto the Dockerfile. - PATH ordering. On Windows,
WindowsAppsand old installs may shadow a newer Python for barepythonbut not for thepylauncher. Preferpy -3there, or fix PATH yourself.
Conda, uv, and Poetry: the same rule in different clothes
Modern environment tools change the commands, never the principle — install in the environment of the interpreter you run:
- conda:
conda activate myenvfirst; inside it,python -m pip installbehaves correctly for anything not on conda-forge. - uv:
uv add requestsoperates on the project environment thatuv runwill use; avoid mixinguv addand a foreign pip invocation on the same folder. - Poetry:
poetry installandpoetry run python yourfile.pyalways meet in the same environment; a straypipinside the folder is the usual source of a mismatch.
Whatever the tool writes its own metadata to, one sentence stays true: the interpreter, its environment, and the installation must be the same one.
Prevention checklist
- Install with
<the python you run> -m pip install ...— never a barepipwhen in doubt. - One venv per project; activate it in every terminal and select it in the editor.
- Keep
requirements.txtor lock files regenerated from the same environment. - Before debugging imports, print
sys.executableandpip --versionand compare. - Restart notebook kernels and terminals after any install.
- Never name a file after a module you intend to import.
Key takeaways
ModuleNotFoundErroris a statement about one specific interpreter: that environment lacks the module.- In most cases, pip and python in your terminal are simply different environments.
- The universal fix is
python -m pip install <package>— installing through the interpreter you run. - Virtual environments end the problem class, not the individual incident.
- Some packages install under one name and import under a different, documented name.
- Local shadowing files, admin installs, containers, and unrestarted kernels are the classic red herrings.
Challenge
Open any environment you are currently unsure about and run the three-line diagnostic yourself: python -c "import sys; print(sys.executable)", pip --version, and python -m pip --version. If the folders differ, fix one project with a venv and confirm the error is gone before touching anything global.
Stuck setting up a reliable environment for a course or project? Ampersand Academy offers one-to-one mentoring in Python and data skills — part of Mahadhi, a development and digital marketing company.
—
FAQ
Because pip belongs to a different environment than the interpreter running the script. Compare pip --version with python -m pip --version; different folders means different teams.
- Why does pip say the package is already installed but the import still fails?
python -m pip install thepackage. Using -m routes the install through the exact interpreter you will import with.
- What single command fixes most cases?
No. The interpreter is healthy; only the wiring between pip and python is wrong. Fix the installation target or create a venv.
- Do I need to reinstall Python to fix this?
Different terminals can resolve different python and pip commands on PATH, or have a venv activated in one and not the other. Each terminal pair must agree.
- Why does the import work in one terminal but fail in another?
VS Code runs the interpreter you selected in the editor, while a plain shell runs whatever PATH resolves. Make both point to the same environment and the behavior matches.
- Why does it work in VS Code but fail when I double-click or use cmd?
It can stop the bleeding for single-user machines, but it still leaves many environments coexisting. A per-project venv is the reliable endgame.
- Is pip install –user a good fix?
Read the original pip output: a compiled dependency error means pip itself could not finish, which is a different failure from import-time module errors. Install the named system component or pick a wheel that bundles it.
- Some packages install but the module needs extra system libraries. How do I know?
Why does pip say the package is already installed but the import still fails?
Because pip belongs to a different environment than the interpreter running the script. Compare pip –version with python -m pip –version; different folders means different teams.
What single command fixes most cases?
python -m pip install thepackage. Using -m routes the install through the exact interpreter you will import with.
Do I need to reinstall Python to fix this?
No. The interpreter is healthy; only the wiring between pip and python is wrong. Fix the installation target or create a venv.
Why does the import work in one terminal but fail in another?
Different terminals can resolve different python and pip commands on PATH, or have a venv activated in one and not the other. Each terminal pair must agree.
Why does it work in VS Code but fail when I double-click or use cmd?
VS Code runs the interpreter you selected in the editor, while a plain shell runs whatever PATH resolves. Make both point to the same environment and the behavior matches.
Is pip install –user a good fix?
It can stop the bleeding for single-user machines, but it still leaves many environments coexisting. A per-project venv is the reliable endgame.
Some packages install but the module needs extra system libraries. How do I know?
Read the original pip output: a compiled dependency error means pip itself could not finish, which is a different failure from import-time module errors. Install the named system component or pick a wheel that bundles it.
Last updated on · Written by Dinesh Kumar R
