crewAIInc/crewAI · error · ImportError

google-genai is required for Gemini file uploads. Install wi

Error message

google-genai is required for Gemini file uploads. Install with: pip install google-genai

What it means

ImportError raised lazily by GeminiFileUploader._get_client when 'from google import genai' fails: the google-genai SDK is not installed. Note the required package is the newer google-genai distribution (not the legacy google-generativeai), so installing the wrong package reproduces the error.

Source

Thrown at lib/crewai-files/src/crewai_files/uploaders/gemini.py:124

            client: Optional pre-instantiated Gemini client.
        """
        self._api_key = api_key or os.environ.get("GOOGLE_API_KEY")
        self._client: Any = client

    @property
    def provider_name(self) -> str:
        """Return the provider name."""
        return "gemini"

    def _get_client(self) -> Any:
        """Get or create the Gemini client."""
        if self._client is None:
            try:
                from google import genai

                self._client = genai.Client(api_key=self._api_key)
            except ImportError as e:
                raise ImportError(
                    "google-genai is required for Gemini file uploads. "
                    "Install with: pip install google-genai"
                ) from e
        return self._client

    def upload(self, file: FileInput, purpose: str | None = None) -> UploadResult:
        """Upload a file to Gemini.

        For FilePath sources, passes the path directly to the SDK which handles
        streaming internally via resumable uploads, avoiding memory overhead.

        Args:
            file: The file to upload.
            purpose: Optional purpose/description (used as display name).

        Returns:
            UploadResult with the file URI and metadata.

View on GitHub (pinned to 754d7323be)

Solutions

  1. pip install google-genai (the correct, current SDK for this uploader).
  2. Uninstall the legacy package if present to avoid confusion: pip uninstall google-generativeai.
  3. Warm the client at startup with uploader._get_client() to fail fast.

Example fix

# before
# pip install google-generativeai  (wrong package)
uploader = GeminiFileUploader(api_key=...)
uploader.upload(file)  # ImportError

# after
# pip install google-genai
uploader = GeminiFileUploader(api_key=...)
uploader._get_client()  # fail fast
uploader.upload(file)
Defensive patterns

Strategy: validation

Validate before calling

from importlib.util import find_spec

if find_spec("google.genai") is None:
    raise RuntimeError("pip install google-genai (not google-generativeai) required")

Try / catch

try:
    uploader.upload(file)
except ImportError as e:
    if "google-genai" in str(e):
        raise RuntimeError("wrong or missing SDK: pip install google-genai") from e
    raise

Prevention

When it happens

Trigger: Constructing GeminiFileUploader and calling upload (which triggers _get_client) when google-genai is missing, or when only the legacy google-generativeai package is installed.

Common situations: Following older tutorials that say pip install google-generativeai; deploying without the Gemini extra; using a notebook kernel whose environment lacks the SDK.

Related errors


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