ModuleNotFoundError: No module named ... usually means Python is using a different environment from the one where the package was installed, or the package name and import name are different.

Use the same interpreter
Install packages through the interpreter that will run your program. This prevents bare pip from targeting another Python installation.
python -m pip install requestspython -c "import requests; print(requests.__version__)"python -c "import sys; print(sys.executable)"
On Windows, try py -m pip. On macOS and Linux, python3 -m pip may be the correct command. Compare the executable path with python -m pip --version.
Activate the project environment
Application dependencies should normally live in a virtual environment:
python -m venv .venv# Windows PowerShell.\.venv\Scripts\Activate.ps1# macOS or Linuxsource .venv/bin/activatepython -m pip install requests
Print sys.executable after activation. If it does not point into .venv, the shell is still using another interpreter.
Check package and import names
PyPI names and import names are not always identical. scikit-learn imports as sklearn, pillow imports as PIL, and python-dateutil imports as dateutil. Follow the package documentation instead of guessing.
Check your project path
Run the command from the project root and avoid local files named requests.py, json.py, or another module you intend to import. A local file can shadow the real package. For your own package, keep a clear folder structure and include __init__.py when appropriate.
Fix the IDE interpreter
In VS Code, open the Command Palette, choose Python: Select Interpreter, and select the interpreter inside .venv. Then open a new terminal. Your IDE and terminal may otherwise use different Python installations.
Reinstall after checking the path
python -m pip uninstall requestspython -m pip install --no-cache-dir requestspython -c "import requests; print(requests.__file__)"
For a project dependency file, use python -m pip install -r requirements.txt. This keeps installation tied to the active interpreter.
Quick checklist
- Read the exact module name in the traceback.
- Use
python -m pip, not barepip. - Print
sys.executable. - Compare the IDE and terminal interpreters.
- Check package and import names separately.
- Look for local files shadowing the module.
Conclusion
Most ModuleNotFoundError issues come from an interpreter mismatch, an inactive virtual environment, or a different import name. Check those causes first, then reinstall only inside the verified environment.


Leave a Reply