Graphify-Labs/graphify · error · ImportError
the 'anthropic' package is required for this backend but is
Error message
the 'anthropic' package is required for this backend but is not installed. Install it with: uv tool install "graphifyy[anthropic]" --force (uv tool), or pip install anthropic (pip/venv install).
What it means
Raised by `_call_claude` when `import anthropic` fails. The native `claude` backend (not the OpenAI compat layer, not claude-cli) calls Anthropic's SDK directly, so the `anthropic` package must be present. The message comes from `_backend_pkg_hint("anthropic", "anthropic")` and includes the exact uv/pip install command.
Source
Thrown at graphify/llm.py:1320
if output_tokens < 50 and backend == "ollama":
print(
"[graphify] warning: ollama returned very few tokens — likely causes: "
"(1) VRAM pressure: check `nvidia-smi` and reduce chunk size with "
"--token-budget (e.g. --token-budget 4096) or set "
"GRAPHIFY_OLLAMA_NUM_CTX to a smaller value; "
"(2) model too small for JSON instruction following — "
"try a larger model with --model (e.g. --model qwen2.5-coder:14b).",
file=sys.stderr,
)
return result
def _call_claude(api_key: str, model: str, user_message: str, max_tokens: int = 8192, *, deep_mode: bool = False, images: list[_ImageRef] | None = None) -> dict:
"""Call Anthropic Claude directly (not via OpenAI compat layer)."""
try:
import anthropic
except ImportError as exc:
raise ImportError(_backend_pkg_hint("anthropic", "anthropic")) from exc
client = anthropic.Anthropic(
api_key=api_key,
base_url=BACKENDS["claude"]["base_url"],
timeout=_resolve_api_timeout(),
max_retries=_resolve_max_retries(),
)
resp = client.messages.create(
model=model,
max_tokens=max_tokens,
system=_extraction_system(deep=deep_mode),
messages=[{"role": "user", "content": _anthropic_content(user_message, images or [])}],
)
raw_content = resp.content[0].text if resp.content else None
result = _parse_llm_json(raw_content or "{}")
result["input_tokens"] = resp.usage.input_tokens if resp.usage else 0
result["output_tokens"] = resp.usage.output_tokens if resp.usage else 0
result["model"] = modelView on GitHub (pinned to 7fe58b0b0f)
Solutions
- Install the extra: `uv tool install "graphifyy[anthropic]" --force` or `pip install anthropic` in the active venv.
- Confirm with `python -c "import anthropic"` using the same interpreter that runs graphify.
- Alternatively switch to `backend="claude-cli"` if you have the Claude Code CLI installed and don't want the SDK.
Example fix
# before pip install graphifyy # after pip install "graphifyy[anthropic]"
Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
if importlib.util.find_spec("anthropic") is None:
raise SystemExit("graphify's claude backend needs: pip install graphifyy[anthropic]") Try / catch
try:
extract_files_direct(files, root, backend="claude")
except ImportError as e:
if "anthropic" in str(e):
subprocess.run([sys.executable, "-m", "pip", "install", "anthropic"], check=True)
extract_files_direct(files, root, backend="claude")
else:
raise Prevention
- Install `graphifyy[anthropic]` whenever ANTHROPIC_API_KEY is part of your standard env, since auto-detection will pick the claude backend.
- Prefer `backend="claude-cli"` on machines where you don't want the SDK dependency.
When it happens
Trigger: Calling `extract_files_direct(..., backend="claude")` (or `detect_backend()` returning `claude` because ANTHROPIC_API_KEY is set) in an environment without the `anthropic` package installed.
Common situations: Installing graphify without the `[anthropic]` extra but having ANTHROPIC_API_KEY exported, so auto-detection selects `claude`; venv drift after a reinstall; CI images that trim optional dependencies.
Related errors
- the '{pkg}' package is required for this backend but is not
- Azure OpenAI requires the openai package. Run: pip install o
- AWS Bedrock extraction requires boto3. Run: pip install grap
- matplotlib not installed. Run: pip install matplotlib
- neo4j driver not installed. Run: pip install neo4j
AI-assisted analysis of Graphify-Labs/graphify@7fe58b0b0f (2026-08-14).
Data as JSON: /api/errors/f01aee6ac197b0ff.
Report an issue: GitHub.