Last modified: Dec 04, 2025 By Alexander Williams

Fix TypeError: 'module' object is not callable

Python errors can be confusing for beginners. One common error is the TypeError: 'module' object is not callable. This error stops your code from running. It often happens due to simple import mistakes. Understanding it is key to fixing it quickly.

This article explains what this error means. We will look at common causes. You will learn how to diagnose and fix the issue. We provide clear examples and solutions. By the end, you will handle this error with confidence.

Understanding the Error Message

The error message is very specific. Python is telling you it tried to "call" a module. In programming, "call" means using parentheses (). You call functions and classes. You cannot call a module object.

A module is a file containing Python code. It groups related functions and classes. You import it to use its contents. The error occurs when you use the module name like a function.

Here is a simple example that causes the error.


# Incorrect: Trying to call the 'datetime' module directly
import datetime

# This line causes the error
current_time = datetime()
    

Traceback (most recent call last):
  File "script.py", line 4, in 
    current_time = datetime()
TypeError: 'module' object is not callable
    

The error traceback points to the exact line. The problem is using datetime(). The datetime is a module, not a function. You need to access the specific class inside it.

Common Cause 1: Confusing Module and Class

This is the most frequent cause. Many Python modules have the same name as a class inside them. The datetime module contains a datetime class. This naming overlap causes confusion.

You import the module but intend to use the class. You then accidentally call the module. The solution is to access the class correctly. You have a few options to do this.

Solution 1: Import the specific class directly. This is often the cleanest approach.


# Correct: Import the datetime class from the datetime module
from datetime import datetime

current_time = datetime.now()  # Now 'datetime' refers to the class
print(current_time)
    

Solution 2: Use the full path to the class. Keep the module import and reference the class inside it.


# Correct: Use the module name to access the class inside it
import datetime

current_time = datetime.datetime.now()  # module.class.method
print(current_time)
    

Common Cause 2: Module Name Shadowing

Another cause is shadowing. You might name your own file after a standard module. Or you might name a variable after an imported module. This redefines the name. The original module is no longer accessible.

For example, you create a file named math.py. Then you try to use the standard math module in another script. Python might import your file instead of the built-in one. This leads to unexpected errors.

Solution: Avoid naming conflicts. Never name your files after Python built-in modules. Do not use common module names for your variables. Check your variable names in the current scope.


# Problem: Variable 'math' shadows the imported module
import math

math = 3.14  # This reassigns 'math' to a float
# The next line will cause: TypeError: 'float' object is not callable
# Because 'math' is no longer a module
result = math.sqrt(4)
    

Common Cause 3: Incorrect Import Statement

Sometimes the import statement itself is wrong. You might think you are importing a function. But you are actually importing the parent module. This happens with packages that have a nested structure.

You need to check the package documentation. Ensure you are importing the correct item. Use the dir() function to list a module's contents. This helps you see what you actually imported.

Solution: Verify your imports. Use print(type(imported_name)) to check. Use dir(imported_name) to see available attributes.


import collections

print(type(collections))  # Output: 
print(dir(collections))   # Shows all items in the module, like 'deque', 'Counter'
    

Step-by-Step Debugging Guide

Follow these steps when you see this error. They will help you find the root cause fast.

1. Read the traceback. Find the line number causing the error. Look at the object name before the parentheses.

2. Check the import. Go to the top of your file. See what you imported with that name. Did you import a module or a function?

3. Check for shadowing. Look for variable assignments. See if you reassigned the imported name later in your code.

4. Use print to inspect. Add print(type(object_name)) before the error line. This tells you what the object really is.

5. Consult documentation. Look up the official docs for the module. Confirm the correct way to use its functions or classes.

Related Python TypeErrors

This error is part of a family of TypeError messages. They all involve trying to use an object incorrectly. Understanding one helps with others.

For example, you might see Fix TypeError: 'method' object is not subscriptable. This happens when you use square brackets on a method.

Another is Fix TypeError: 'bool' object is not callable. This occurs if you accidentally call a boolean value.

Also common is Fix TypeError: 'NoneType' is Not Iterable. This error appears when you try to loop over a None value.

Conclusion

The TypeError: 'module' object is not callable is a common beginner mistake. It stems from confusing a module with a callable item inside it. The fix is usually straightforward.

Always check your imports. Be mindful of naming conflicts. Use the module.attribute syntax when in doubt. Apply the debugging steps to pinpoint the issue quickly.

Mastering this error makes you a better Python programmer. You will understand Python's import system better. You will also debug other TypeError messages more easily. Keep coding and learning from these mistakes.