TypeError: 'module' object is not callable

Python · updated 2026-11-03

Raised when you put parentheses after a module object. Many modules contain a class or function with the same name as the module, so import x followed by x() calls the module, not the thing inside it.

Traceback (most recent call last):
  File "/app/report.py", line 8, in <module>
    for row in tqdm(rows):
               ^^^^^^^^^^
TypeError: 'module' object is not callable

Quick fix

Import the class or function from the module, not the module itself: from tqdm import tqdm, from datetime import datetime, from pprint import pprint. Or keep import x and call x.x().

  1. Find the call on the failing line and the import for that name at the top of the file.
  2. Change import name to from name import name (or call name.name()).
  3. Check for a local file or folder with the same name that is being imported instead.
  4. In shared code, keep one import style per module so the same name does not mean different things in different files.
python
# Before
import datetime
import tqdm
now = datetime()          # TypeError: 'module' object is not callable
for row in tqdm(rows): ...

# After
from datetime import datetime
from tqdm import tqdm
now = datetime.now()
for row in tqdm(rows): ...

Why it happens

Same name for the module and what it contains

datetime, tqdm, pprint, glob, socket and decimal all contain a function or class named like the module, which makes import x / x() an easy slip.

Your own package with an __init__.py

A package app/client/ with client.py inside: import app.client gives the package; the class is app.client.client.Client unless __init__.py re-exports it.

Import style changed in one file

A refactor that switched from from x import x to import x elsewhere leaves calls that still expect the function.

Other fixes

  • Linters (pyright, mypy) flag calls on modules before the code runs.
  • Re-export public names in a package __init__.py so imports read the way callers expect.

Same error, other wording

  • TypeError: 'module' object is not callable (datetime)
  • TypeError: 'module' object is not subscriptable
  • AttributeError: module 'datetime' has no attribute 'now'

Let your coding agent catch the next one

Runheed records this error in production with the stack trace, the breadcrumbs before it and the agent session that shipped the code, and serves it to Claude Code, Cursor or any MCP client. With it connected, you can ask:

> Find the 'module object is not callable' errors in production, show me each call and its import, and fix the import to bring in the function or class directly.

Plans from $29/moSee what your agent readsSee the setupCancel any time from the billing portal

Related errors

References: Python tutorial: modules and imports, Python docs: built-in exceptions (TypeError)