{"record":{"id":"3a03a0da371e56b7","repo":"langchain-ai/deepagents","slug":"the-selected-python-runtime-does-not-contain-deep","errorCode":null,"errorMessage":"The selected Python runtime does not contain Deep Agents Code dependencies.","messagePattern":"The selected Python runtime does not contain Deep Agents Code dependencies\\.","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"critical","filePath":"libs/code/deepagents_code/built_in_skills/deepagents-thread-inspector/scripts/inspect_sessions.py","lineNumber":50,"sourceCode":"\ndef _has_runtime() -> bool:\n    try:\n        for module, symbol in _RUNTIME_IMPORTS:\n            getattr(importlib.import_module(module), symbol)\n    except (AttributeError, ImportError):\n        return False\n    return True\n\n\ndef _ensure_runtime() -> None:\n    if _has_runtime():\n        return\n    if os.environ.get(\"DEEPAGENTS_THREAD_INSPECTOR_REEXEC\") == \"1\":\n        msg = (\n            \"The selected Python runtime does not contain Deep Agents Code \"\n            \"dependencies.\"\n        )\n        raise SystemExit(msg)\n\n    candidates: list[Path] = []\n    for command in (\"dcode\", \"deepagents-code\"):\n        executable = shutil.which(command)\n        if not executable:\n            continue\n        launcher = Path(executable).resolve()\n        try:\n            first_line = launcher.read_text(encoding=\"utf-8\").splitlines()[0]\n        except (OSError, UnicodeDecodeError, IndexError):\n            first_line = \"\"\n        if first_line.startswith(\"#!\"):\n            candidates.append(Path(first_line[2:].strip()))\n        candidates.extend((launcher.parent / \"python\", launcher.parent / \"python3\"))\n\n    seen: set[str] = set()\n    for candidate in candidates:\n        candidate_key = str(candidate.absolute())","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/built_in_skills/deepagents-thread-inspector/scripts/inspect_sessions.py#L32-L68","documentation":"The thread-inspector script re-executes itself with a Python that has Deep Agents Code dependencies installed; if the re-executed runtime still cannot import them, the loop guard `DEEPAGENTS_THREAD_INSPECTOR_REEXEC=1` is set and `_ensure_runtime` aborts with this SystemExit message instead of retrying forever. It means the selected interpreter is missing the required packages (or `dcode`/`deepagents-code` cannot be located on PATH as a fallback).","triggerScenarios":"Running `inspect_sessions.py` in an environment where the current Python lacks deepagents-code, the script re-execs via a candidate found on PATH (dcode/deepagents-code) or venv, but the re-executed interpreter still cannot import the dependencies — detected via the `DEEPAGENTS_THREAD_INSPECTOR_REEXEC=1` env var.","commonSituations":"A broken or stale `dcode` shim on PATH pointing to an environment without dependencies; running with `uv run` or a bare system python whose site-packages lacks the package; a partially uninstalled/moved virtualenv.","solutions":["Install Deep Agents Code into the active environment (e.g. `uv pip install -e libs/code` or `pip install deepagents-code`).","Check that `which dcode` / `which deepagents-code` points to a working installation; fix or remove a broken shim.","Run the script via the `dcode`-managed environment (e.g. `uv run dcode` context) rather than a bare interpreter.","Clear the stale `DEEPAGENTS_THREAD_INSPECTOR_REEXEC` env var if it leaked into the shell and masks a fresh attempt."],"exampleFix":"// before\n$ python scripts/inspect_sessions.py --thread abc   # bare system python, no deps\n// after\n$ uv run python scripts/inspect_sessions.py --thread abc  # or: dcode python scripts/inspect_sessions.py ...","handlingStrategy":"fallback","validationCode":"import importlib.util\nif importlib.util.find_spec('deepagents_code') is None:\n    import sys; sys.exit('Run via dcode/uv environment: dcode python scripts/inspect_sessions.py')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the script inside the environment where deepagents-code is installed (uv run / project venv).","Verify `which dcode` resolves to a working install before using the inspector.","Keep DEEPAGENTS_THREAD_INSPECTOR_REEXEC unset in shells to avoid masking a legitimate re-exec attempt.","Install editable deps (`uv pip install -e libs/code`) when working from a checkout."],"tags":["environment","python-runtime","missing-dependency","script"],"backgroundTag":"missing-runtime-dependency","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}