{"record":{"id":"09a58d51e4431fdd","repo":"headroomlabs-ai/headroom","slug":"anthropic-package-required-install-with-pip-inst","errorCode":null,"errorMessage":"anthropic package required. Install with: pip install anthropic","messagePattern":"anthropic package required\\. Install with: pip install anthropic","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"headroom/evals/batch_compression_eval.py","lineNumber":1038,"sourceCode":"        self._token_counter = TokenCounter(self.model)\n        self._llm_client = self._init_llm_client()\n\n    def _get_default_model(self, provider: str) -> str:\n        \"\"\"Get default model for provider.\"\"\"\n        return {\n            \"anthropic\": \"claude-sonnet-4-20250514\",\n            \"openai\": \"gpt-4o\",\n        }.get(provider, \"claude-sonnet-4-20250514\")\n\n    def _init_llm_client(self) -> Any:\n        \"\"\"Initialize LLM client.\"\"\"\n        if self.provider == \"anthropic\":\n            try:\n                import anthropic\n\n                return anthropic.Anthropic()\n            except ImportError as e:\n                raise ImportError(\n                    \"anthropic package required. Install with: pip install anthropic\"\n                ) from e\n        elif self.provider == \"openai\":\n            try:\n                import openai\n\n                return openai.OpenAI()\n            except ImportError as e:\n                raise ImportError(\n                    \"openai package required. Install with: pip install openai\"\n                ) from e\n        else:\n            raise ValueError(f\"Unknown provider: {self.provider}\")\n\n    def _call_llm(self, messages: list[dict[str, Any]]) -> str:\n        \"\"\"Call LLM and return response text.\"\"\"\n        if self.provider == \"anthropic\":\n            response = self._llm_client.messages.create(","sourceCodeStart":1020,"sourceCodeEnd":1056,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/evals/batch_compression_eval.py#L1020-L1056","documentation":"Raised by _init_llm_client() in the batch compression eval harness when provider == 'anthropic' but `import anthropic` fails. The eval driver lazy-imports the SDK only for the selected provider and converts ImportError into a targeted message; it is chained (`from e`) so the true import failure (not installed, wrong interpreter, or broken install) stays visible in the traceback.","triggerScenarios":"Constructing the batch-compression eval driver with provider='anthropic' in an environment lacking the anthropic package. Note the constructor also defaults the model to claude-sonnet-4-20250514 for this provider, so merely selecting the provider without the SDK installed triggers it at client init.","commonSituations":"headroom installed without the anthropic extra; evals run under the system Python while anthropic was pip-installed in a venv; broken anthropic install (missing transitive deps like httpx) also surfaces here as ImportError.","solutions":["pip install anthropic into the interpreter running the evals","Verify with `python -c \"import anthropic\"` in that same environment; fix venv/interpreter mismatch if it fails","Ensure ANTHROPIC_API_KEY is set too — the import will succeed but anthropic.Anthropic() will be the next failure without it"],"exampleFix":"# before\nrunner = BatchCompressionEval(provider=\"anthropic\", ...)\n# ImportError: anthropic package required.\n\n# after\n# pip install anthropic\n# export ANTHROPIC_API_KEY=sk-ant-...\nrunner = BatchCompressionEval(provider=\"anthropic\", ...)","handlingStrategy":"validation","validationCode":"try:\n    import anthropic  # noqa: F401\nexcept ImportError:\n    raise SystemExit(\"Eval requires the anthropic SDK: pip install anthropic\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install eval LLM extras (anthropic/openai) in the eval environment up front","Check `python -c 'import anthropic'` in the exact interpreter before launching eval runs","Set ANTHROPIC_API_KEY in the same step, since client construction is the immediate next failure"],"tags":["dependency","import","evals","anthropic","llm"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}