crewAIInc/crewAI · error · AttributeError

module 'crewai' has no attribute {name!r}

Error message

module 'crewai' has no attribute {name!r}

What it means

crewai's package __init__ implements PEP 562 lazy importing via __getattr__: known heavy names (e.g. Memory) import on first access, and anything not in the _LAZY_IMPORTS mapping raises AttributeError('module crewai has no attribute ...'). This most often surfaces with 'from crewai import X' where X was renamed, moved, or is genuinely not exported.

Source

Thrown at lib/crewai/src/crewai/__init__.py:66

_suppress_pydantic_deprecation_warnings()

__version__ = "1.15.16"

_LAZY_IMPORTS: dict[str, tuple[str, str]] = {
    "Memory": ("crewai.memory.unified_memory", "Memory"),
}


def __getattr__(name: str) -> Any:
    """Lazily import heavy modules (e.g. Memory → lancedb) on first access."""
    if name in _LAZY_IMPORTS:
        module_path, attr = _LAZY_IMPORTS[name]
        mod = importlib.import_module(module_path)
        val = getattr(mod, attr)
        globals()[name] = val
        return val
    raise AttributeError(f"module 'crewai' has no attribute {name!r}")


try:
    from crewai.agents.agent_builder.base_agent import BaseAgent as _BaseAgent
    from crewai.agents.agent_builder.base_agent_executor import (
        BaseAgentExecutor as _BaseAgentExecutor,
    )
    from crewai.agents.tools_handler import ToolsHandler as _ToolsHandler
    from crewai.experimental.agent_executor import AgentExecutor as _AgentExecutor
    from crewai.hooks.llm_hooks import LLMCallHookContext as _LLMCallHookContext
    from crewai.tools.tool_types import ToolResult as _ToolResult
    from crewai.utilities.prompts import (
        StandardPromptResult as _StandardPromptResult,
        SystemPromptResult as _SystemPromptResult,
    )

    _base_namespace: dict[str, type] = {
        "Agent": Agent,

View on GitHub (pinned to 754d7323be)

Solutions

  1. Check the export list: python -c 'import crewai; print(crewai.__all__)' and import the correct public name.
  2. If the class exists but moved, import from its submodule directly (e.g. from crewai.memory.unified_memory import Memory).
  3. Pin/align crewai versions between development and production; consult the changelog for renames.
  4. Fix typos in the attribute name.

Example fix

# before
from crewai import MemoryConfig  # AttributeError if not exported

# after
from crewai.memory.config import MemoryConfig  # import from the owning submodule
Defensive patterns

Strategy: type-guard

Validate before calling

import crewai

name = 'Memory'
if name not in getattr(crewai, '_LAZY_IMPORTS', {}) and not hasattr(crewai, name):
    raise AttributeError(f'crewai does not export {name!r} - check version/renames')

Type guard

import crewai

def exports(name: str) -> bool:
    return hasattr(crewai, name) or name in getattr(crewai, '_LAZY_IMPORTS', {})

Try / catch

try:
    from crewai import Memory
except AttributeError as e:
    # fall back to the canonical submodule path
    from crewai.memory.unified_memory import Memory

Prevention

When it happens

Trigger: Accessing an attribute not listed in _LAZY_IMPORTS and not imported at package top level - e.g. crewai.SomeClass, or 'from crewai import Agent' variants where the name is misspelled/removed; also copy/pasted code targeting a different crewai version.

Common situations: Upgrading crewai and hitting renamed/removed public names; IDE autocompleting a private symbol; tutorials referencing exports that only exist in newer/older versions; old memory of names like crewai.Utilities.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/09f440a6b6bafbef. Report an issue: GitHub.