langchain-ai/deepagents · error · ImportError
Cannot determine location for {package_root}
Error message
Cannot determine location for {package_root} What it means
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.
Source
Thrown at libs/code/deepagents_code/model_config.py:1401
if cached is not None: # `is not None` so empty profile dicts are cached
return cached
parts = module_path.split(".")
package_root = parts[0]
spec = importlib.util.find_spec(package_root)
if spec is None:
msg = f"Package {package_root} is not installed"
raise ImportError(msg)
# Determine the package directory from the spec.
if spec.origin:
package_dir = Path(spec.origin).parent
elif spec.submodule_search_locations:
package_dir = Path(next(iter(spec.submodule_search_locations)))
else:
msg = f"Cannot determine location for {package_root}"
raise ImportError(msg)
# Build the path to the target file (e.g., data/_profiles.py).
relative_parts = parts[1:] # ["data", "_profiles"]
profiles_path = package_dir.joinpath(
*relative_parts[:-1], f"{relative_parts[-1]}.py"
)
if not profiles_path.exists():
msg = f"Profile module not found: {profiles_path}"
raise ImportError(msg)
file_spec = importlib.util.spec_from_file_location(module_path, profiles_path)
if file_spec is None or file_spec.loader is None:
msg = f"Could not create module spec for {profiles_path}"
raise ImportError(msg)
module = importlib.util.module_from_spec(file_spec)
file_spec.loader.exec_module(module)View on GitHub (pinned to a1af029e6e)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
import importlib.util
spec = importlib.util.find_spec(package_root)
if spec is None or (spec.origin is None and not spec.submodule_search_locations):
raise SystemExit(f"Package {package_root} is installed but has no importable location; reinstall it") Try / catch
try:
profiles = get_model_profiles(module_path)
except ImportError as exc:
logging.warning("profiles unavailable: %s", exc)
profiles = {} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Could not import module '{module_path}' for provider '{provi
- Missing dependencies for '{provider}' sandbox. {install_hint
- Class '{class_name}' not found in module '{module_path}'
- Package {package_root} is not installed
- Profile module not found: {profiles_path}
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/e9259a3828a76bb9.
Report an issue: GitHub.