{"record":{"id":"e9259a3828a76bb9","repo":"langchain-ai/deepagents","slug":"cannot-determine-location-for-package-root","errorCode":null,"errorMessage":"Cannot determine location for {package_root}","messagePattern":"Cannot determine location for (.+?)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/model_config.py","lineNumber":1401,"sourceCode":"        if cached is not None:  # `is not None` so empty profile dicts are cached\n            return cached\n\n        parts = module_path.split(\".\")\n        package_root = parts[0]\n\n        spec = importlib.util.find_spec(package_root)\n        if spec is None:\n            msg = f\"Package {package_root} is not installed\"\n            raise ImportError(msg)\n\n        # Determine the package directory from the spec.\n        if spec.origin:\n            package_dir = Path(spec.origin).parent\n        elif spec.submodule_search_locations:\n            package_dir = Path(next(iter(spec.submodule_search_locations)))\n        else:\n            msg = f\"Cannot determine location for {package_root}\"\n            raise ImportError(msg)\n\n        # Build the path to the target file (e.g., data/_profiles.py).\n        relative_parts = parts[1:]  # [\"data\", \"_profiles\"]\n        profiles_path = package_dir.joinpath(\n            *relative_parts[:-1], f\"{relative_parts[-1]}.py\"\n        )\n\n        if not profiles_path.exists():\n            msg = f\"Profile module not found: {profiles_path}\"\n            raise ImportError(msg)\n\n        file_spec = importlib.util.spec_from_file_location(module_path, profiles_path)\n        if file_spec is None or file_spec.loader is None:\n            msg = f\"Could not create module spec for {profiles_path}\"\n            raise ImportError(msg)\n\n        module = importlib.util.module_from_spec(file_spec)\n        file_spec.loader.exec_module(module)","sourceCodeStart":1383,"sourceCodeEnd":1419,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/model_config.py#L1383-L1419","documentation":"After find_spec locates the root package, _load_provider_profiles derives the package directory from spec.origin or spec.submodule_search_locations. If neither yields a usable location (e.g. a namespace-ish or oddly-created spec), it raises ImportError('Cannot determine location for {package_root}') because it cannot build the filesystem path to the _profiles.py file.","triggerScenarios":"Calling _discover_available_models() or get_model_profiles() for a package whose ModuleSpec has origin=None (e.g. namespace packages, packages installed via unusual loaders, or stub/frozen modules) and no submodule_search_locations entries.","commonSituations":"Shadowing a real package with an empty namespace directory of the same name on sys.path; a broken/partial install where dist-info exists but the package directory does not; running under tooling that injects fake specs (some test runners, zipapps).","solutions":["Inspect the spec: `python -c \"import importlib.util as u; s=u.find_spec('<package_root>'); print(s.origin, s.submodule_search_locations)\"` and fix the install (reinstall the package).","Remove shadowing directories or files with the same name as the package earlier on sys.path.","If it is a namespace package by design, ensure it has __init__.py or proper search locations so importlib can resolve a directory."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import importlib.util\nspec = importlib.util.find_spec(package_root)\nif spec is None or (spec.origin is None and not spec.submodule_search_locations):\n    raise SystemExit(f\"Package {package_root} is installed but has no importable location; reinstall it\")","typeGuard":null,"tryCatchPattern":"try:\n    profiles = get_model_profiles(module_path)\nexcept ImportError as exc:\n    logging.warning(\"profiles unavailable: %s\", exc)\n    profiles = {}","preventionTips":["Avoid naming your own directories the same as installed packages (shadowing).","Prefer regular packages with __init__.py over namespace packages for providers.","Reinstall the package if the environment was copied or partially deleted."],"tags":["python","import","packaging"],"backgroundTag":"module-not-found","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}