headroomlabs-ai/headroom · error · ImportError
anthropic package required. Install with: pip install anthro
Error message
anthropic package required. Install with: pip install anthropic
What it means
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.
Source
Thrown at headroom/evals/batch_compression_eval.py:1038
self._token_counter = TokenCounter(self.model)
self._llm_client = self._init_llm_client()
def _get_default_model(self, provider: str) -> str:
"""Get default model for provider."""
return {
"anthropic": "claude-sonnet-4-20250514",
"openai": "gpt-4o",
}.get(provider, "claude-sonnet-4-20250514")
def _init_llm_client(self) -> Any:
"""Initialize LLM client."""
if self.provider == "anthropic":
try:
import anthropic
return anthropic.Anthropic()
except ImportError as e:
raise ImportError(
"anthropic package required. Install with: pip install anthropic"
) from e
elif self.provider == "openai":
try:
import openai
return openai.OpenAI()
except ImportError as e:
raise ImportError(
"openai package required. Install with: pip install openai"
) from e
else:
raise ValueError(f"Unknown provider: {self.provider}")
def _call_llm(self, messages: list[dict[str, Any]]) -> str:
"""Call LLM and return response text."""
if self.provider == "anthropic":
response = self._llm_client.messages.create(View on GitHub (pinned to 322425c43b)
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
Example fix
# before runner = BatchCompressionEval(provider="anthropic", ...) # ImportError: anthropic package required. # after # pip install anthropic # export ANTHROPIC_API_KEY=sk-ant-... runner = BatchCompressionEval(provider="anthropic", ...)
Defensive patterns
Strategy: validation
Validate before calling
try:
import anthropic # noqa: F401
except ImportError:
raise SystemExit("Eval requires the anthropic SDK: pip install anthropic") Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- openai package required. Install with: pip install openai
- HuggingFace datasets required for this loader. Install with:
- Magika is required for ML-based content detection. Install w
- Unknown provider: {self.provider}
- anthropic package required. Install with: pip install anthro
AI-assisted analysis of headroomlabs-ai/headroom@322425c43b (2026-08-15).
Data as JSON: /api/errors/09a58d51e4431fdd.
Report an issue: GitHub.