crewAIInc/crewAI · error · ImportError
anthropic is required for Anthropic file uploads. Install wi
Error message
anthropic is required for Anthropic file uploads. Install with: pip install anthropic
What it means
ImportError raised lazily on first use of the Anthropic uploader's sync client (_get_client): importing anthropic failed, so the SDK is not installed in the active environment. The check happens at client-creation time, not at uploader construction, so instantiation succeeds and the error surfaces on the first upload call.
Source
Thrown at lib/crewai-files/src/crewai_files/uploaders/anthropic.py:56
"""
self._api_key = api_key or os.environ.get("ANTHROPIC_API_KEY")
self._client: Any = client
self._async_client: Any = async_client
@property
def provider_name(self) -> str:
"""Return the provider name."""
return "anthropic"
def _get_client(self) -> Any:
"""Get or create the Anthropic client."""
if self._client is None:
try:
import anthropic
self._client = anthropic.Anthropic(api_key=self._api_key)
except ImportError as e:
raise ImportError(
"anthropic is required for Anthropic file uploads. "
"Install with: pip install anthropic"
) from e
return self._client
def _get_async_client(self) -> Any:
"""Get or create the async Anthropic client."""
if self._async_client is None:
try:
import anthropic
self._async_client = anthropic.AsyncAnthropic(api_key=self._api_key)
except ImportError as e:
raise ImportError(
"anthropic is required for Anthropic file uploads. "
"Install with: pip install anthropic"
) from e
return self._async_clientView on GitHub (pinned to 754d7323be)
Solutions
- Install the SDK in the active environment: pip install anthropic (or uv add 'crewai-files[anthropic]' if the extra exists).
- Verify the right interpreter is being used: python -c "import anthropic" in the same venv that runs the app.
- Pre-warm the client right after constructing the uploader (call uploader._get_client()) so a missing SDK fails fast at startup instead of mid-job.
Example fix
# before uploader = AnthropicUploader(api_key=...) result = uploader.upload(file) # ImportError at job time # after # install first: pip install anthropic uploader = AnthropicUploader(api_key=...) uploader._get_client() # fail fast at startup if SDK missing result = uploader.upload(file)
Defensive patterns
Strategy: validation
Validate before calling
def anthropic_sdk_available() -> bool:
try:
import anthropic # noqa: F401
return True
except ImportError:
return False
if not anthropic_sdk_available():
raise RuntimeError("install `pip install anthropic` before enabling file uploads") Try / catch
try:
uploader.upload(file)
except ImportError as e:
if "anthropic" in str(e):
logger.error("missing dependency: pip install anthropic")
raise Prevention
- Declare the anthropic dependency in the same environment manifest that enables file uploads.
- Warm uploader._get_client() during startup wiring to fail fast.
- Add a smoke test that imports each optional SDK your uploaders use.
When it happens
Trigger: Constructing AnthropicUploader(...) and calling upload(file) when the anthropic package is not installed in the current interpreter, or when a different virtualenv/Python than the one where crewai-files was installed is being used.
Common situations: Using file uploads without installing the [anthropic] extra, running under a container or notebook kernel with a different environment, or a dependency conflict that uninstalled anthropic.
Related errors
- boto3 is required for Bedrock S3 file uploads. Install with:
- aioboto3 is required for async Bedrock S3 file uploads. Inst
- google-genai is required for Gemini file uploads. Install wi
- openai is required for OpenAI file uploads. Install with: pi
- This subcommand requires the full crewai package. Install it
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/6532f9e0e3f886f7.
Report an issue: GitHub.