ProjectStack
python

ModuleNotFoundError: No module named

Python 3.6+ introduced ModuleNotFoundError as a specific subclass of ImportError for missing modules. The package isn't installed in the Python environment you're currently using.

Common causes

  • The package isn't installed: run pip install <package-name>
  • Using the wrong Python environment — you installed the package globally but are running a virtual environment
  • The virtual environment wasn't activated before running the script
  • You installed with pip3 but are running python (which might point to Python 2 on some systems)

How to fix it

  1. Install the package: pip install <package-name> or python -m pip install <package-name>
  2. Check which Python is being used: which python or python --version
  3. Activate your virtual environment: source venv/bin/activate
  4. List installed packages to verify: pip list | grep <package>

Example

Traceback (most recent call last): File "app.py", line 1, in <module> from flask import Flask ModuleNotFoundError: No module named 'flask'

Running a Flask app without first installing Flask via pip install flask

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.