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_client

View on GitHub (pinned to 754d7323be)

Solutions

  1. Install the SDK in the active environment: pip install anthropic (or uv add 'crewai-files[anthropic]' if the extra exists).
  2. Verify the right interpreter is being used: python -c "import anthropic" in the same venv that runs the app.
  3. 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

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


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/6532f9e0e3f886f7. Report an issue: GitHub.