ErrorPython
ModuleNotFoundError: No module named
Why Python's ModuleNotFoundError happens even when a package looks installed, how mismatched environments cause it, and how to fix each cause.
Last updated
ErrorPython
ModuleNotFoundError: No module named 'requests'
What it means: Python tried to import a module by that name and couldn't find it anywhere on `sys.path` — it isn't installed where this interpreter looks, or the name itself is wrong.
Likely causes
Most probable first — with how to confirm.
- 1.The package isn't installed in the environment you're actually running — check `pip show requests`; and especially check you're not in a different virtualenv or conda env than the one you installed into (`which python` or `where python`).
- 2.You installed it with a different Python/pip than the one executing the script — on systems with multiple Pythons, `pip install` and `python script.py` can silently point at different interpreters.
- 3.It's a local module, and Python can't find it because you ran the script from the wrong directory, the package is missing an `__init__.py` on an older Python version, or it isn't on `PYTHONPATH`.
- 4.You mistyped the import name or confused the PyPI package name with the actual import name — most packages match, but a few well-known ones (like `python-dotenv`, imported as `dotenv`) don't.
Fixes
Safest first; destructive ones are called out.
- →Install into the environment you're actually running: activate the right virtualenv or conda env first, then run `python -m pip install requests` so it definitely targets the interpreter you'll execute the script with.
- →Check `python -c "import sys; print(sys.executable)"` and `print(sys.path)` to see exactly which interpreter and search path are in play, especially in mixed Python 2/3 or multi-venv setups.
- →For local or first-party modules, run the script from the project root, or use `python -m package.module`, so relative imports resolve; add an `__init__.py` if the package needs one.
- →Double-check the import name against the package's own documentation — the install name and the import name diverge for a fair number of common packages.