apache/beam · error · ImportError

Vertex AI Model Monitoring v2 dependencies are not…

Error message

Vertex AI Model Monitoring v2 dependencies are not installed.

What it means

VertexModelMonitoringV2.create_model_monitor requires google-cloud-aiplatform's model monitoring (v2) module. If the ml_monitoring import is None (dependencies absent), it raises ImportError stating the Vertex AI Model Monitoring v2 dependencies are not installed.

Solutions

  1. Install the dependency: pip install apache-beam[gcp] or pip install google-cloud-aiplatform>=1.x with model monitoring support
  2. Add google-cloud-aiplatform to pipeline_options requirements_file so workers install it
  3. Upgrade google-cloud-aiplatform to a version that includes the model_monitoring v2 module

Example fix

# before
python -m apache_beam.runners.worker... # missing aiplatform
# after
pip install 'apache-beam[gcp]' 'google-cloud-aiplatform[model-monitoring]'
Defensive patterns

Strategy: validation

Validate before calling

try:
    from google.cloud.aiplatform import model_monitoring as ml_monitoring
except ImportError:
    raise RuntimeError('Install google-cloud-aiplatform with model monitoring support')

Try / catch

try:
    monitor.create_model_monitor()
except ImportError:
    logger.error('Vertex AI Model Monitoring v2 deps missing; add google-cloud-aiplatform to requirements')
    raise

Prevention

When it happens

Trigger: Calling create_model_monitor() (directly or via the setup method of the DoFn) in an environment where the aiplatform SDK lacks model monitoring support or the google-cloud-aiplatform extra is not installed.

Common situations: Running on Beam workers with the default apache_beam image that lacks the aiplatform extra; forgetting to include google-cloud-aiplatform in requirements.txt of the pipeline.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/a12c14dfe0043f52. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/ml/inference/vertex_ai_model_monitoring_v2.py:89

    self.location = location
    self.display_name = display_name
    self.model_name = model_name
    self.model_version_id = model_version_id
    self.model_monitoring_schema = model_monitoring_schema
    self.training_dataset = training_dataset
    self.tabular_objective_spec = tabular_objective_spec
    self.model_monitor_id = model_monitor_id
    self.explanation_spec = explanation_spec
    self.output_spec = output_spec
    self.notification_spec = notification_spec
    self.credentials = credentials
    self.manager = None
    self.kwargs = kwargs

  def create_model_monitor(self):
    """Creates a ModelMonitor with a deterministic ID or retrieves existing one."""
    if ml_monitoring is None:
      raise ImportError(
          'Vertex AI Model Monitoring v2 dependencies are not installed.')

    try:
      return ml_monitoring.model_monitors.ModelMonitor.create(
          model_name=self.model_name,
          model_version_id=self.model_version_id,
          training_dataset=self.training_dataset,
          display_name=self.display_name,
          model_monitoring_schema=self.model_monitoring_schema,
          tabular_objective_spec=self.tabular_objective_spec,
          output_spec=self.output_spec,
          notification_spec=self.notification_spec,
          explanation_spec=self.explanation_spec,
          project=self.project_id,
          location=self.location,
          credentials=self.credentials,
          model_monitor_id=self.model_monitor_id,
          **self.kwargs,

View on GitHub (pinned to 12126d8942)