apache/beam · error · ImportError
Google Cloud Recommendation AI not supported for this…
Error message
Google Cloud Recommendation AI not supported for this execution environment (could not import google.cloud.recommendationengine).
What it means
Module-level guard in recommendations_ai.py: the google.cloud.recommendationengine package could not be imported, so the Recommendations AI connector is unusable in this environment. The error surfaces at module import, not at transform runtime.
Solutions
- Install the client library: pip install google-cloud-recommendation-ai
- Install the Beam extra that bundles GCP connectors: pip install 'apache_beam[gcp]'
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at sdks/python/apache_beam/ml/gcp/recommendations_ai.py:42 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/6c40e18c60f1458d.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/ml/gcp/recommendations_ai.py:42
from typing import Sequence
from cachetools.func import ttl_cache
from google.api_core.retry import Retry
from apache_beam import pvalue
from apache_beam.metrics import Metrics
from apache_beam.options.pipeline_options import GoogleCloudOptions
from apache_beam.transforms import DoFn
from apache_beam.transforms import ParDo
from apache_beam.transforms import PTransform
from apache_beam.transforms.util import GroupIntoBatches
from apache_beam.utils import retry
# pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports
try:
from google.cloud import recommendationengine
except ImportError:
raise ImportError(
'Google Cloud Recommendation AI not supported for this execution '
'environment (could not import google.cloud.recommendationengine).')
# pylint: enable=wrong-import-order, wrong-import-position, ungrouped-imports
__all__ = [
'CreateCatalogItem',
'WriteUserEvent',
'ImportCatalogItems',
'ImportUserEvents',
'PredictUserEvent'
]
FAILED_CATALOG_ITEMS = "failed_catalog_items"
MAX_RETRIES = 5
@ttl_cache(maxsize=128, ttl=3600)
def get_recommendation_prediction_client():View on GitHub (pinned to 12126d8942)