ShareYourGroupShareYourGroupPython

ModuleNotFoundError: no module named

A ModuleNotFoundError means an import line named a module that Python could not find. Nothing after that line runs.

import maths

What Python says

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

Cause 1: the name is misspelt

The module is math, not maths. Module names are exact and are almost always in small letters. Some names that catch people out:

You wroteThe module is
import mathsimport math
import Randomimport random
import dateimport datetime

Check the spelling in the official documentation or in the example you are following.

Cause 2: the package is not installed

Python comes with a standard library: math, random, datetime, csv, os, json and many more. These never need installing. Packages made by other people, such as those for charts or spreadsheets, must be installed before the first use with the tool pip. The command is typed in the Command Prompt or terminal, not inside Python:

python -m pip install package-name

On some systems the command starts with python3 or, on Windows, py. Use the same word that you use to start Python itself.

Before you install anything, check that the package name is the right one. The name you install is sometimes different from the name you import, and badly spelt names can lead to fake packages. Take the install command from the package's own official page.

Cause 3: installed, but for a different Python

This is the most confusing case. A computer can have more than one Python: one from python.org, one that came with another program, one inside a code editor's environment. pip installed the package for one of them, and your program runs with another.

To see which Python is running your program:

import sys
print(sys.executable)
print(sys.version)

Then install with that same Python by using the form python -m pip install ..., which ties pip to the Python you name. In an editor, check which interpreter is selected, usually shown in a corner of the window.

Cause 4: your own file is not where Python looks

You can import your own files. If helpers.py sits in the same folder as your program, import helpers works. It fails when the file is in another folder, when the name is misspelt, or when you included the ending: write import helpers, never import helpers.py.

Cause 5: a file named like a module

If you save your program as random.py and write import random, Python finds your file first. The import "works", but then random.randint fails with an AttributeError. The cure is to rename your file.

ImportError: cannot import name

A close relative. The module was found, but the particular name you asked for is not in it.

from math import square

What Python says

Traceback (most recent call last):
  File "example.py", line 1, in <module>
    from math import square
ImportError: cannot import name 'square' from 'math' (unknown location)

math has sqrt but no square. Check the spelling of the name after import.

A calm routine

  1. Read the module name in the message. Is it spelt correctly, in the right case?
  2. Is it part of the standard library? Then the spelling is the only possible fault.
  3. If it is an outside package, install it with python -m pip install, using the same Python that runs your program.
  4. If it is your own file, check the folder and the file name.

Importing is explained in lesson 17. All the lessons on this site use only the standard library, so you can finish the whole course without installing anything.

Other error messages

Examples on this page were run with Python 3.14 on 12 November 2026. The output shown is the real output.

This is an independent learning site. It is not connected with or approved by the Python Software Foundation. "Python" is a trademark of the Python Software Foundation and is used here only to name the language.