{"record":{"id":"df0cc05760bf0c9b","repo":"langchain-ai/langchain","slug":"module-package-r-module-name-r-not-found-e","errorCode":null,"errorMessage":"module '{package!r}.{module_name!r}' not found ({err})","messagePattern":"module '(.+?)\\.(.+?)' not found \\((.+?)\\)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/_import_utils.py","lineNumber":39,"sourceCode":"    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":21,"sourceCodeEnd":42,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/_import_utils.py#L21-L42","documentation":"Raised by the same import utility when an explicit `module_name` is requested (`import_module(f'.{module_name}', package=package)`) and that submodule does not exist. Unlike the attribute case this raises ImportError, chained from the original ModuleNotFoundError, telling you exactly which dotted submodule under `package` failed to import.","triggerScenarios":"A lazy `__getattr__` maps a public name to `(module_name, attr_name)` — e.g. `('rag', 'create_react_agent')` — and the call requests a name whose backing module path is absent, or importing that module itself fails because one of its internal imports targets a missing optional dependency (ModuleNotFoundError propagates from any depth of the failed import).","commonSituations":"Version skew: code written against a newer langchain-core where a module was added, or a refactor that moved `foo.bar` to `foo._bar`. Also occurs when a lazily imported integration module has an undeclared third-party dependency that isn't installed, making the submodule unimportable even though the file exists.","solutions":["Verify the submodule path exists in your installed version: `uv run python -c \"import langchain_core; print(langchain_core.__version__)\"` and inspect the package directory.","If the module moved, update the import to the current path from the version's docs/changelog.","If the failure is a transitive missing dependency, install it (`uv add <dep>`) — the chained `err` in the message names the module Python couldn't find.","Align versions with the lockfile (`uv sync --all-groups`) when mixing manually installed packages."],"exampleFix":"# before (module renamed in v0.4)\nfrom langchain_core.agents import create_agent  # ImportError: module ... not found\n\n# after\nfrom langchain.agents import create_agent","handlingStrategy":"try-catch","validationCode":"import importlib.util\n\ndef module_available(dotted: str) -> bool:\n    return importlib.util.find_spec(dotted) is not None\n\nassert module_available(\"langchain_core.messages\")","typeGuard":null,"tryCatchPattern":"try:\n    thing = import_attr(\"langchain_core.x\", module_name=\"y\", attr_name=\"Thing\")\nexcept ImportError as e:\n    # chained ModuleNotFoundError names the missing module/dependency\n    log.warning(\"optional feature unavailable: %s\", e)\n    thing = None  # degrade gracefully for optional integrations","preventionTips":["Use importlib.util.find_spec to feature-detect optional modules before importing them.","Read the chained exception — it distinguishes 'module moved' from 'dependency not installed'.","Smoke-test imports for every langchain version you support in a version matrix job."],"tags":["imports","version-skew","langchain-core"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}