← All Python errors

Python error explained

ModuleNotFoundError: what it means and how to fix it

Python cannot find the module you tried to import.

The message

ModuleNotFoundError: No module named 'maths'

What it means

import looks for a module by its exact name. If the name is misspelt, or the package is not installed, you get a ModuleNotFoundError. The standard library (math, random, datetime, json and many more) is always available.

Common causes

  • A typo, like maths instead of math or Random instead of random
  • A third-party package that is not installed (pip install it on your own computer)
  • Naming your own file the same as a module, like random.py

Example that raises it

import maths

print(maths.sqrt(144))

The fix

import math

print(math.sqrt(144))

Tip: Module names are lower case and American spelling: math, not maths. Never name your own script after a module you want to import.

Fix the broken version yourself in the editor on this page. It runs real Python in your browser.

Start the free lessons More Python errors