langchain-ai/deepagents · error · ImportError

Package {package_root} is not installed

Error message

Package {package_root} is not installed

What it means

_load_provider_profiles resolves a dotted module path (e.g. `provider.data._profiles`) by first locating the top-level package with importlib.util.find_spec. If the root package cannot be found on sys.path, it raises ImportError('Package {package_root} is not installed'). The library throws this because provider profiles are loaded lazily from optional provider packages, so a missing dependency is reported as an explicit, actionable ImportError rather than a silent empty profile set.

Source

Thrown at libs/code/deepagents_code/model_config.py:1392

        The `_PROFILES` dictionary from the module, or an empty dict if
            the module has no such attribute.

    Raises:
        ImportError: If the package is not installed or the profile module
            cannot be found on disk.
    """
    with _provider_profiles_lock:
        cached = _provider_profiles_cache.get(module_path)
        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}"

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Install the missing provider package into the active interpreter: `pip install <package_root>` or the matching extras, e.g. `uv pip install deepagents-code[<provider>]`.
  2. Verify you are in the intended environment: `which python` / `python -c "import <package_root>"`.
  3. Check the module_path configured for the provider for typos; the first dotted segment must be the real installed distribution's import name.

Example fix

// before (module path points at uninstalled package)
module_path = "anthropic_provider.data._profiles"  # ImportError
// after (install the package first)
# pip install anthropic-provider
module_path = "anthropic_provider.data._profiles"
Defensive patterns

Strategy: fallback

Validate before calling

import importlib.util
if importlib.util.find_spec(package_root) is None:
    raise SystemExit(f"Install missing provider package: {package_root}")

Try / catch

try:
    profiles = get_model_profiles(module_path)
except ImportError:
    profiles = {}  # fall back to default profiles and warn the user

Prevention

When it happens

Trigger: Calling _discover_available_models() or get_model_profiles() when the top-level package name in the configured module_path is not importable — i.e. find_spec(parts[0]) returns None because the provider package is not installed in the active environment.

Common situations: The provider extra is not installed (e.g. missing `pip install deepagents-code[anthropic]`); the app runs in a venv/poetry/uv environment different from the one where providers were installed; a typo'd or renamed package name in configuration; the package was uninstalled or upgraded with a new import name.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/8914b0e671051ff3. Report an issue: GitHub.