{"record":{"id":"6d08839215b07c45","repo":"langchain-ai/langchain","slug":"module-package-r-has-no-attribute-attr-name-r","errorCode":null,"errorMessage":"module '{package!r}' has no attribute {attr_name!r}","messagePattern":"module '(.+?)' has no attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/_import_utils.py","lineNumber":33,"sourceCode":"        attr_name: The name of the attribute to import.\n        module_name: The name of the module to import from.\n\n            If `None`, the attribute is imported from the package itself.\n        package: The name of the package where the module is located.\n\n    Raises:\n        ImportError: If the module cannot be found.\n        AttributeError: If the attribute does not exist in the module or package.\n\n    Returns:\n        The imported attribute.\n    \"\"\"\n    if module_name == \"__module__\" or module_name is None:\n        try:\n            result = import_module(f\".{attr_name}\", package=package)\n        except ModuleNotFoundError:\n            msg = f\"module '{package!r}' has no attribute {attr_name!r}\"\n            raise AttributeError(msg) from None\n    else:\n        try:\n            module = import_module(f\".{module_name}\", package=package)\n        except ModuleNotFoundError as err:\n            msg = f\"module '{package!r}.{module_name!r}' not found ({err})\"\n            raise ImportError(msg) from None\n        result = getattr(module, attr_name)\n    return result\n","sourceCodeStart":15,"sourceCodeEnd":42,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/_import_utils.py#L15-L42","documentation":"Raised by `import_attr`-style lazy-import helper in langchain_core._import_utils when it tries to import `package.attr_name` as a submodule (module_name is `\"__module__\"` or None) and Python raises ModuleNotFoundError — i.e. the package has no submodule by that name, so the requested attribute cannot exist. It is re-raised as AttributeError to mimic normal `module.attr` access failing on a missing attribute.","triggerScenarios":"A lazy module `__getattr__` (e.g. `langchain_core.some_pkg.__getattr__('MissingThing')`) dispatches to `import_attr(package='langchain_core.some_pkg', attr_name='MissingThing')` and there is no `langchain_core/some_pkg/missing_thing.py` (or `missing_thing` submodule of any casing). Also triggered by `importlib.import_module('pkg.Missing')` style typos routed through this helper.","commonSituations":"Typo in a public API name (`from langchain_core.messages import HummanMessage`), using a name that exists only in a newer/older langchain-core version, or referencing an integration class that lives in a separate partner package that isn't installed. Because it surfaces as AttributeError, users often misread it as a missing re-export rather than a wrong name.","solutions":["Check the exact spelling/casing against the module's `__init__.py` exports or the API reference for your installed version.","If the symbol moved, import from its new location (changelogs and DeprecationWarning messages usually name the new path).","If it lives in a partner package, install that package (`uv add langchain-openai` etc.) instead of expecting it in core.","Pin/upgrade to the version whose API surface you coded against (`uv sync` to honor the lockfile)."],"exampleFix":"# before\nfrom langchain_core.messages import HummanMessage\n\n# after\nfrom langchain_core.messages import HumanMessage","handlingStrategy":"try-catch","validationCode":"import importlib.util\n\ndef submodule_exists(package: str, attr: str) -> bool:\n    return importlib.util.find_spec(f\"{package}.{attr}\") is not None","typeGuard":"def is_exported(module, name: str) -> bool:\n    return getattr(module, \"__all__\", None) is None or name in module.__all__","tryCatchPattern":"try:\n    from langchain_core.messages import HumanMessage\nexcept AttributeError:\n    # wrong name or wrong version: check __all__ of the installed version\n    import langchain_core.messages as m\n    raise SystemExit(f\"not exported here: {sorted(m.__all__)}\")","preventionTips":["Let the editor complete imports from the installed package rather than typing names from memory.","Pin langchain-core via the lockfile so the API surface matches what you coded against.","Check `pkg.__all__` (or dir(pkg)) when an attribute-style import fails — it distinguishes typo from version gap."],"tags":["imports","lazy-loading","langchain-core"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}