apache/seatunnel · error · ImportError
anthropic package required for AI_PROVIDER=anthropic…
Error message
anthropic package required for AI_PROVIDER=anthropic. Install it: pip install anthropic
What it means
AnthropicProvider initializes the Anthropic Messages API client and imports the third-party 'anthropic' package lazily. If the package is not installed, it raises ImportError with an install hint before any API call is made.
Solutions
- Run: pip install anthropic in the active environment
- Install with the CLI's LLM extra if provided (e.g. pip install 'seatunnel-cli[anthropic]')
- Verify with 'python -c "import anthropic"' that the same interpreter running the CLI has the package
Example fix
// before export AI_PROVIDER=anthropic seatunnel-cli ... # ImportError // after pip install anthropic export AI_PROVIDER=anthropic
Defensive patterns
Strategy: try-catch
Validate before calling
python -c "import anthropic" || pip install anthropic
Try / catch
try:
provider = get_provider()
except ImportError as e:
print(f'Missing LLM dependency: {e}. Run: pip install anthropic')
sys.exit(2) Prevention
- Install CLI LLM extras in the same venv used to run the CLI
- Pin anthropic in your requirements/setup
- Verify imports in CI before invoking LLM features
- Avoid switching AI_PROVIDER without installing its package
When it happens
Trigger: AI_PROVIDER=anthropic selects AnthropicProvider and its __init__ runs 'import anthropic', which fails because the package is absent from the current Python environment.
Common situations: Installed seatunnel-cli without the anthropic extra; running inside a fresh venv/container lacking the dependency; forgot 'pip install anthropic' after switching AI_PROVIDER.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- ANTHROPIC_API_KEY environment variable is required for…
- bedrock-mantle provider requires: pip install openai…
- openai package required for AI_PROVIDER=openai. Install it…
- Bedrock Mantle response ended with status
- OPENAI_API_KEY environment variable is required for…
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/9aa4065af84f06a6.
Report an issue: GitHub.
Appendix: source
Thrown at seatunnel-cli/seatunnel_cli/llm_provider.py:478
yield {"type": "tool_input_delta", "tool_use_id": current_tool_id or "", "delta": delta["toolUse"].get("input", "")}
elif "contentBlockStop" in event:
if current_tool_id:
yield {"type": "tool_stop", "tool_use_id": current_tool_id}
current_tool_id = None
elif "messageStop" in event:
yield {"type": "message_stop", "stop_reason": event["messageStop"].get("stopReason", "end_turn")}
# ─── Anthropic Provider ───
class AnthropicProvider(LLMProvider):
"""Anthropic Messages API provider (direct, not via Bedrock)."""
def __init__(self):
try:
import anthropic
except ImportError:
raise ImportError(
"anthropic package required for AI_PROVIDER=anthropic. "
"Install it: pip install anthropic"
)
api_key = os.environ.get("ANTHROPIC_API_KEY")
if not api_key:
raise ValueError("ANTHROPIC_API_KEY environment variable is required for AI_PROVIDER=anthropic")
self._client = anthropic.Anthropic(api_key=api_key)
self._model_id = os.environ.get("ANTHROPIC_MODEL", "claude-sonnet-4-20250514")
self._fast_model_id = os.environ.get("ANTHROPIC_SMALL_FAST_MODEL", "claude-haiku-4-5-20251001")
@property
def provider_name(self) -> str:
return "anthropic"
@property
def model_id(self) -> str:View on GitHub (pinned to cf67b549a7)