The Module Object Is Not Callable error means you called a module like a function; import the function you meant to call or fix a name clash.
You’re coding along, you run your script, and Python throws a line that feels rude: “TypeError: ‘module’ object is not callable”. This one shows up in quick prototypes, bigger apps, notebooks, and even clean code after a small rename.
This guide helps you spot the exact trigger fast, then fix it in a way that won’t boomerang the next time you refactor. You’ll see the common patterns, what to check in your imports, and the naming traps that make Python treat a module like a function call.
Why This Error Happens In Plain Terms
Python only lets you “call” callables. Functions are callable. Classes are callable. Instances can be callable if they implement __call__. A module is not callable, so Python raises a TypeError when it sees parentheses right after a module name.
Most of the time, you meant to call something inside the module, not the module itself. The rest of the time, you accidentally overwrote a function name with a module name, or imported the wrong thing because two names look alike.
What “callable” means in code
When Python evaluates thing(), it checks whether thing can be invoked. A module can hold functions, classes, and constants, yet the module object itself isn’t set up to be invoked with parentheses.
How it looks when a module gets called by mistake
# You installed a package named "requests"
import requests
# This calls the module object, not a function inside it
requests()
If you run that, Python complains because requests is a module reference. You probably wanted a function like requests.get(), or you expected requests to be a function due to a naming mix-up.
Module Object Is Not Callable In Python When Names Clash
The fastest fixes come from one question: what is the name on the left side of the parentheses, right on the failing line? Once you know that name, you can confirm whether it’s a module, then trace how it got there.
Pattern 1: Calling a package instead of a function
This happens when a library has a top-level package name that feels like it should be a function. The fix is nearly always “call a member inside the module.”
- Call a function inside the module — Replace
module()withmodule.some_function()ormodule.SomeClass()as documented. - Import the symbol you mean — Swap
import moduleforfrom module import some_function, then callsome_function().
Pattern 2: Importing the module when you meant the function
# You meant to call datetime(...)
import datetime
# datetime is a module here, so this fails
datetime(2026, 2, 8)
The fix is to import the class from the module, or reference it through the module name.
# Option A: reference the class through the module
import datetime
dt = datetime.datetime(2026, 2, 8)
# Option B: import the class directly
from datetime import datetime
dt = datetime(2026, 2, 8)
Pattern 3: A local file shadows the real library
This one bites even experienced developers. If your project has a file named random.py, json.py, requests.py, or similar, Python may import your local file instead of the library you thought you were using. Then your code calls what you think is a function, yet it’s your module.
- Rename the local file — Use a name that won’t collide with stdlib or installed packages, then delete any stale
__pycache__files. - Check what got imported — Print
module.__file__to see the path Python loaded.
import json
print(json.__file__)
Pattern 4: You reassigned a function name to a module
Sometimes the import is correct, then a later line overwrites the name. After that, your call hits a module object.
from mypkg import tools # tools is a module
from mypkg.tools import slugify # slugify is a function
# Later, an accidental reassignment
slugify = tools
# Now this fails with: 'module' object is not callable
slugify("Hello")
- Search for reassignments — Look for the name with
=in your file, then pick a new variable name. - Use clearer naming — Keep module names and function names distinct, even if they feel related.
Fast Checks That Pinpoint The Cause
When you’re staring at a stack trace, speed matters. These checks take seconds and usually reveal the root cause right away.
Check the failing name’s type
Right before the failing call, print the object and its type. If it’s a module, Python will show it plainly.
# Right before the line that crashes:
print(target, type(target))
print(getattr(target, "__file__", "no __file__ attribute"))
- Confirm it’s a module — If
type(target)prints, you’re calling a module. - Check where it came from — If
__file__points to your project folder, you may have a shadowing file.
Inspect the import statement that created the name
Scan the top of the file for how the name was introduced. The difference between these two lines is the whole story:
import datetime # datetime is a module
from datetime import datetime # datetime is a class
If the call site uses parentheses on a name introduced by import X, confirm whether X is meant to be called or whether a member should be referenced.
Search for shadowing without guessing
If you suspect shadowing, check the module path that got loaded and compare it to what you expected. This avoids the “I think I imported the real one” trap.
- Print the module file path — Use
print(module.__file__)to see the loaded location. - Check your working directory — If you’re running from inside a package folder, imports may resolve differently than you expect.
- Clear cache after renames — Delete
__pycache__folders so old bytecode doesn’t confuse runs.
Fix Patterns That Work In Real Projects
Once you know which pattern you’re in, the fix is straightforward. The real win is picking the version that stays clear months later when you reread the file.
Fix imports to match how you call the name
If you want to call thing(), make sure thing is a function or class, not the module. These swaps are the most common clean repairs:
- Import a function directly — Change
import pkgtofrom pkg import func, then callfunc(). - Call through the module — Keep
import pkg, then callpkg.func()so the namespace stays explicit. - Avoid wildcard imports — Skip
from pkg import *; it makes collisions easy and debugging slow.
Fix name collisions in your own modules
If a local file or folder shares a name with a library, rename yours. That feels annoying for five minutes and saves hours later. After renaming, update imports and clear caches.
# Bad: shadows the standard library module "json"
# json.py
# Better:
# json_helpers.py
- Rename the file and folder — Pick a name that says what it does, not what it resembles.
- Delete stale caches — Remove
__pycache__so your next run loads the new names cleanly. - Rerun from project root — Run scripts with a consistent working directory to reduce surprise imports.
Fix circular imports that mask the real symbol
Circular imports can lead to partially initialized modules. In that state, a name that should point at a function may point at a module reference instead, or be missing and replaced during debugging. The repair is to break the cycle, not to add more import tricks.
- Move shared code — Put shared helpers in a third module that both sides can import.
- Import inside a function — Use local imports only when it keeps dependencies clean and readable.
- Trim side effects — Avoid running work at import time; keep module top-level code light.
Fix calls on packages that expose a callable elsewhere
Some packages expose a callable class or factory function one level down. If you wrote package(), scan the docs or autocomplete results for the callable entry point.
# Wrong
import package
package()
# Right (style depends on the library)
from package import factory
factory()
# Or
import package
package.factory()
Habits That Stop This Error From Coming Back
After you fix the crash, a couple of small habits help you avoid seeing it again. These aren’t “rules for rules’ sake.” They keep names stable as your project grows.
Use naming that separates modules, functions, and instances
When a module and function share a similar name, keep your variable names distinct so calls read cleanly.
- Keep module names noun-like —
date_utils,http_client,image_io. - Keep function names verb-like —
parse_date(),fetch_url(),load_image(). - Keep instances specific —
client,session,parser, not the module name repeated.
Prefer explicit imports in shared code
In shared libraries, explicit imports make stack traces easier to read and reduce collisions. If you see a name in code, you can usually find where it came from without hunting.
- Use module namespaces when it helps —
import datetimethendatetime.datetimereads clearly in many codebases. - Import symbols when calls dominate — If a function is used constantly,
from pkg import funccan keep code tidy.
Let tools catch shadowing early
Linters and type checkers often flag suspicious imports and reassignments long before runtime. Even a light setup can point to “you’re calling a module” moments while you’re still editing.
- Run a linter on save — It can warn about redefined names and unused imports that hide bugs.
- Use type hints where it fits — When a name is annotated as a function, reassigning it to a module stands out fast.
- Keep tests close to imports — A tiny import test that runs in CI can catch shadowing after a rename.
Reference Table And A Clean Debug Flow
When you hit this again, you don’t need to reread everything. Use the table to match the symptom, then run the short flow right after it.
| What You See | Most Likely Cause | What To Do |
|---|---|---|
datetime(...) fails after import datetime |
Module imported, class not referenced | Use datetime.datetime(...) or from datetime import datetime |
| A well-known library loads from your project folder | Local file shadows the library | Rename your file, clear __pycache__, rerun |
| A name used to be a function, now it’s a module | Reassignment or import collision | Search for = name, rename variables, make imports explicit |
| It fails only in one run mode or notebook cell order | Circular import or partial init | Break the cycle, move shared code, limit top-level work |
Debug flow you can run in under a minute
- Go to the exact failing line — Identify the name right before the parentheses.
- Print the type and file path — Check
type(name)andgetattr(name, "__file__", ""). - Trace the name’s import — Find the import line that created that name in the current file.
- Search for reassignment — Look for the name on the left side of
=after imports. - Apply the smallest clean fix — Import the callable you meant, or call the member through the module.
If you’re still stuck after those steps, the clue is almost always in the module file path you printed. When it points somewhere you didn’t expect, you’ve found the real cause.
Once you patch it, run your test suite or rerun the failing command from a clean start. That confirms the fix holds and that the same name won’t flip back on the next run.
One last note: if you keep seeing module object is not callable across different scripts, do a quick scan of your project for files named after popular packages or stdlib modules. That single cleanup prevents a lot of repeat pain.
When you see this error again, treat it like a signpost, not a mystery. Python is telling you exactly what it received, and once you align your imports and names, the crash disappears.
For completeness, here’s the phrase one more time in context: the error module object is not callable appears when parentheses are applied to a module reference rather than a callable symbol.
If you want a quick sanity check line to keep handy, this works in most cases: print the object, print its type, print its file path, then fix the import or the name collision that put a module there.
That’s it. You don’t need tricks. You just need the right symbol on the left side of ().
Note: The main keyword appears exactly in headings twice and in body twice, per request.
