ModuleNotFoundError: No module named '…'

  • Python

You may see

ModuleNotFoundError: No module named 'cv2'
ModuleNotFoundError: No module named 'serial'
ModuleNotFoundError: No module named 'tensorflow'
ModuleNotFoundError: No module named 'mediapipe'
ModuleNotFoundError: No module named 'ultralytics'

Why it happens

  • The package isn't installed.
  • The venv isn't switched on.
  • VS Code uses another Python.
  • The install name differs: cv2 comes from opencv-python, serial from pyserial.

How to fix it

  1. Switch the venv on. Your prompt should start with (venv).
  2. Run python -m pip install opencv-python (or pyserial, ultralytics, tensorflow, mediapipe).
  3. In VS Code: Ctrl+Shift+P > Python: Select Interpreter and pick the venv.
  4. If pip says no version is found, your Python may be too new for that package. Use an older Python (check the package's page).

It worked if: python -c "import cv2; print(cv2.__version__)" prints a number.

Seen in a real run (some lines are close variants of it). Produced with Python 3.13 on Windows.

Didn't help? Search another error or ask us.