mem0ai/mem0 · error · ImportError

google-auth is required for GCP authentication. Install with

Error message

google-auth is required for GCP authentication. Install with: pip install google-auth

What it means

Raised at import time of mem0.utils.gcp_auth when the google-auth package is not installed. The module unconditionally imports google.oauth2.service_account and google.auth in a try/except and converts ImportError into this actionable message. Anything that pulls in a GCP-related provider (Vertex AI embedder, Vertex AI vector search, Gemini via service account) will fail at import with this error.

Source

Thrown at mem0/utils/gcp_auth.py:10

import os
import json
from typing import Optional, Dict, Any

try:
    from google.oauth2 import service_account
    from google.auth import default
    import google.auth.credentials
except ImportError:
    raise ImportError("google-auth is required for GCP authentication. Install with: pip install google-auth")


class GCPAuthenticator:
    """
    Centralized GCP authentication handler that supports multiple credential methods.

    Priority order:
    1. service_account_json (dict) - In-memory service account credentials
    2. credentials_path (str) - Path to service account JSON file
    3. Environment variables (GOOGLE_APPLICATION_CREDENTIALS)
    4. Default credentials (for environments like GCE, Cloud Run, etc.)
    """

    @staticmethod
    def get_credentials(
        service_account_json: Optional[Dict[str, Any]] = None,
        credentials_path: Optional[str] = None,
        scopes: Optional[list] = None

View on GitHub (pinned to 001c235229)

Solutions

  1. pip install google-auth in the active environment
  2. Better: install the provider's full extra, e.g. pip install 'mem0ai[google]' or add google-auth to requirements.txt alongside the vertexai packages
  3. Verify with python -c "import google.oauth2.service_account"
  4. If using Docker, rebuild the image after adding the dependency

Example fix

# before: ImportError: google-auth is required ...
from mem0 import Memory

# after
# pip install google-auth google-cloud-aiplatform
from mem0 import Memory
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util
if importlib.util.find_spec('google.oauth2.service_account') is None:
    raise ConfigError('google-auth missing — pip install google-auth before using GCP providers')

Try / catch

try:
    from mem0.utils import gcp_auth
except ImportError as e:
    if 'google-auth is required' in str(e):
        raise ConfigError('add google-auth to requirements') from e
    raise

Prevention

When it happens

Trigger: Importing mem0.embeddings.vertexai or mem0.vector_stores.vertex_ai_vector_search (which transitively import gcp_auth) in an environment without google-auth; a fresh install of mem0ai without extras; a CI image that only installs the core package.

Common situations: Using Vertex AI config without installing GCP extras; dependency conflicts where pip resolved google-auth out; multiple virtualenvs and running from the wrong one.

Understand the failure class

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/f763f5b0ec846511. Report an issue: GitHub.