Python errors / ModuleNotFoundError

ModuleNotFoundError: No module named

Python couldn't find the module to import: its name is spelled differently, the file isn't in the project, or the package isn't installed here.

ModuleNotFoundError: No module named 'maths'

Check these first

  1. Spelling and capitals. import math, not maths or Math.
  2. Your own files. import helper needs a file named exactly helper.py in the same project.
  3. Packages. Some packages aren't available in an online editor, and some import under a different name than the one you install.

Causes and fixes

1 Spelling and capitals

Module names are exact and usually all lowercase: math, random, datetime, numpy.

Broken
import maths
print(maths.pi)
ModuleNotFoundError: No module named 'maths'
Fixed
import math
print(math.pi)
3.141592653589793

2 Your own file isn't in the project

When you split a program into files, from helper import greet looks for a file named helper.py next to yours. Add it with the + button beside the file tabs, with exactly that name.

3 A package this editor doesn't have

Python's own modules, like math, random and json, are always there, and so are popular packages such as NumPy, pandas, Matplotlib, scikit-learn and SciPy. Large ones like TensorFlow and PyTorch, and ones that need a desktop or a web server, aren't: run those on your own computer after pip install.

4 The import name isn't the install name

Some packages import under another name: opencv-python is import cv2, scikit-learn is import sklearn, beautifulsoup4 is import bs4, pillow is import PIL and pyyaml is import yaml.

5 A name that isn't in the module

from math import squareroot fails because math has no squareroot. Check the spelling of the name after import (here sqrt). Two of your own files importing each other give the same error: move what they share into a third file.

Still stuck?