TypeError: 'module' object is not callable (Fix)

This error happens when Python sees a module where it expected something it can call with parentheses.

Beginners often run into this after writing code like math(16) or json(text). The problem is that math and json are modules. They contain functions and classes, but the module itself is not a function.

Quick fix

import math

# Wrong:
# result = math(16)

# Right:
result = math.sqrt(16)
print(result)

Output:

4.0

A module is a container for functions, classes, and variables. Call something inside the module, not the module itself.

What this error means

Python found a module object where it expected something callable.

A callable is something you can use with parentheses, such as:

  • a function
  • a class
  • some special objects that behave like functions

A module is different. It groups related code together, but you do not call a module with ().

For example:

import math

print(type(math))

Output:

<class 'module'>

If you want to inspect this more, see Python type() explained.

Common example that causes the error

A very common mistake looks like this:

import math

print(math(10))

This raises:

TypeError: 'module' object is not callable

Why?

  • import math imports the math module
  • math is now the name of that module
  • math(10) tries to call the module like a function

But math is not a function. It is a module.

Fix 1: Call the function inside the module

Use dot notation to access a function inside the module.

Example with math

import math

print(math.sqrt(10))

Output:

3.1622776601683795

Example with random

import random

print(random.randint(1, 5))

Example output:

3

Example with json

import json

text = '{"name": "Ana"}'
data = json.loads(text)
print(data)

Output:

{'name': 'Ana'}

If you are not sure what a module contains, you can inspect it with dir() or read a module overview such as the Python math module overview or Python json module overview.

Fix 2: Import the function directly

If you only need one function, you can import that function directly.

from math import sqrt

print(sqrt(10))

Output:

3.1622776601683795

This works because sqrt is a function, so sqrt(10) is valid.

Compare these two styles:

import math
print(math.sqrt(10))
from math import sqrt
print(sqrt(10))

Both are correct. The important part is that you call the function, not the module.

If imports still feel confusing, read how imports work in Python.

Fix 3: Check for name collisions

Sometimes the problem is not your function call. The problem is that a name points to a module when you did not expect it to.

Case 1: Reusing a name

import math

# math is the module here
print(type(math))

If you thought math was a function, the import statement shows otherwise.

Case 2: Your file name shadows a real module

This is a very common beginner problem.

For example, if your file is named random.py, this can interfere with importing Python's real random module.

A file structure like this can cause trouble:

random.py
main.py

And in main.py:

import random

print(random(1, 5))

This is wrong for two reasons:

  • random is being called like a function
  • your local file name may be shadowing the real module

A better fix is:

  • rename your file to something else, like my_random_tools.py
  • delete any __pycache__ folder if needed
  • import the real module again

Then use the correct function:

import random

print(random.randint(1, 5))

If Python cannot import the module you expect, you may also want to read ImportError: No module named X.

Common modules beginners misuse this way

These modules are often called by mistake:

  • math
  • random
  • json
  • datetime
  • os

Examples of wrong code:

import math
math(5)
import random
random(1, 10)
import json
json('{"a": 1}')

Correct versions:

import math
print(math.sqrt(5))
import random
print(random.randint(1, 10))
import json
print(json.loads('{"a": 1}'))

For more examples, see the Python random module overview.

How to debug it step by step

When you see this error, use this checklist.

1. Find the name directly before the parentheses

In code like this:

math(10)

The name before the parentheses is math.

That is the object Python is trying to call.

2. Check how that name was imported

Look for lines like:

import math

or:

from math import sqrt

These two imports create different names.

  • import math gives you the module name math
  • from math import sqrt gives you the function name sqrt

3. Print the type

import math

print(type(math))
print(math)

Possible output:

<class 'module'>
<module 'math' from '...'>

If it says module, then you know why calling it fails.

4. See what the module contains

import math

print(dir(math))

This shows the names inside the module, such as sqrt, ceil, and floor.

5. Call a function inside the module instead

import math

print(math.sqrt(16))

6. Check for local files that shadow real modules

If you have files named math.py, json.py, random.py, or datetime.py, rename them.

You can also inspect Python's import path:

import sys
print(sys.path)

That helps when Python is importing from a place you did not expect.

How this differs from similar errors

This error is specific: it means the module itself was called.

Different from TypeError: 'list' object is not callable

That error means you called a list like a function.

Example:

numbers = [1, 2, 3]
numbers(0)

That is a different problem. See TypeError: 'list' object is not callable.

Different from AttributeError: module has no attribute

That error means the module exists, but the name after the dot is wrong.

Example:

import math
print(math.square_root(4))

Here, Python found the module, but square_root is not a valid attribute.

That is different from calling the module itself. See AttributeError: module has no attribute.

Common causes

This error usually comes from one of these mistakes:

  • Using import module_name and then calling module_name()
  • Forgetting the function name after the module name
  • Confusing a module with a class or function
  • Importing the module when you meant to import a function
  • Naming your own file the same as a module and creating import confusion

Useful debugging commands

These commands can help you confirm what a name refers to:

print(type(math))
print(math)
print(dir(math))
import sys; print(sys.path)

Use them when you are not sure whether something is:

  • a module
  • a function
  • a class
  • a local file being imported by mistake

FAQ

Why does Python say a module is not callable?

Because you used parentheses on a module name, but only functions, classes, and some other objects can be called.

How do I know if something is a module?

Use type(name) or print(name). A module often appears like this:

<module 'math' ...>

Can I ever call a module directly?

No. You call functions or classes inside the module, not the module itself.

What if I imported the wrong thing?

Change the import statement.

For example, if you want to call sqrt() directly, use:

from math import sqrt

print(sqrt(9))

Why does this happen with my own file names?

If your file has the same name as a real module, Python may import your file instead of the standard library module. That can lead to confusing behavior and hard-to-read errors.

See also

If you want to avoid this error in future code, start by checking the object's type, fixing the import, and learning how Python resolves module names during import.