Python ModuleNotFoundError

ErrorIntermediateSeverity: LowPython

ModuleNotFoundError: No module named ..., even though pip install succeeded.

Symptoms

  • ModuleNotFoundError: No module named ..., even though pip install succeeded.

Cause

The library was installed into a different Python interpreter from the one running the code, usually because the virtual environment was not activated or another interpreter was selected in the editor.

Fix

  • Create and activate an environment: python -m venv .venv, then .venv\Scripts\activate on Windows or source .venv/bin/activate on Linux and macOS.
  • Install with python -m pip install ... to be sure it is the same interpreter.
  • Select the .venv interpreter in VS Code.

Prevention

  • State in the context file: always use .venv.

Sources

  1. Python Docs: venv