{"record":{"id":"88a0c6132acd8fdb","repo":"apache/beam","slug":"google-cloud-dataflow-runner-not-available-please-install","errorCode":null,"errorMessage":"Google Cloud Dataflow runner not available, please install apache_beam[gcp]","messagePattern":"Google Cloud Dataflow runner not available, please install apache_beam\\[gcp\\]","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/dataflow/dataflow_metrics.py","lineNumber":281,"sourceCode":"    }\n\n\ndef main(argv):\n  \"\"\"Print the metric results for the dataflow --job_id and --project.\n\n  Instead of running an entire pipeline which takes several minutes, use this\n  main method to display MetricResults for a specific --job_id and --project\n  which takes only a few seconds.\n  \"\"\"\n  # TODO(https://github.com/apache/beam/issues/19452): The MetricResults do not\n  # show translated step names as the job_graph is not provided to\n  # DataflowMetrics. Import here to avoid adding the dependency for local\n  # running scenarios.\n  try:\n    # pylint: disable=wrong-import-order, wrong-import-position\n    from apache_beam.runners.dataflow.internal import apiclient\n  except ImportError:\n    raise ImportError(\n        'Google Cloud Dataflow runner not available, '\n        'please install apache_beam[gcp]')\n  if argv[0] == __file__:\n    argv = argv[1:]\n  parser = argparse.ArgumentParser()\n  parser.add_argument(\n      '-j', '--job_id', type=str, help='The job id to query metrics for.')\n  parser.add_argument(\n      '-p',\n      '--project',\n      type=str,\n      help='The project name to query metrics for.')\n  flags = parser.parse_args(argv)\n\n  # Get a Dataflow API client and set its project and job_id in the options.\n  options = PipelineOptions()\n  gcloud_options = options.view_as(GoogleCloudOptions)\n  gcloud_options.project = flags.project","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/dataflow/dataflow_metrics.py#L263-L299","documentation":"This ImportError is raised by DataflowMetrics (and the Dataflow runner generally) when the Dataflow-specific client libraries cannot be imported. The 'apache_beam.runners.dataflow.internal.apiclient' module depends on extra Google Cloud packages (google-api-client, google-cloud-dataflow-client, etc.) that are only installed with the 'gcp' extra of apache-beam. The library raises it lazily so local, non-GCP usage never needs the dependency.","triggerScenarios":"Instantiating DataflowMetrics (e.g. results = pipeline.result.metrics()) or otherwise touching the Dataflow metrics API when apache-beam was installed without the [gcp] extra, so the apiclient import fails.","commonSituations":"Installing with 'pip install apache-beam' instead of 'pip install apache-beam[gcp]'; slim/venv deployments with Google Cloud extras stripped; running a Dataflow metrics query from a local environment with only core Beam installed.","solutions":["Install the GCP extras: pip install 'apache-beam[gcp]'","Verify the internal import works: python -c \"from apache_beam.runners.dataflow.internal import apiclient\"","If dependency conflicts block the upgrade, install the minimal GCP packages (google-api-client, google-cloud-dataflow-client) into the environment.","If you do not actually need Dataflow, use a local runner (DirectRunner) instead of DataflowMetrics."],"exampleFix":"// before\npip install apache-beam\nresults = pipeline.result.metrics()\n// after\npip install 'apache-beam[gcp]'\nresults = pipeline.result.metrics()","handlingStrategy":"fallback","validationCode":"try:\n    from apache_beam.runners.dataflow.internal import apiclient\nexcept ImportError:\n    raise SystemExit(\"Install GCP extras: pip install 'apache-beam[gcp]'\")","typeGuard":null,"tryCatchPattern":"try:\n    results = pipeline.result.metrics()\nexcept ImportError:\n    results = None  # metrics unavailable without [gcp] extras","preventionTips":["Always install 'apache-beam[gcp]' for Dataflow projects","Pin the Beam extra in requirements.txt/setup.py extras_require","Smoke-test the apiclient import in CI before Dataflow jobs"],"tags":["python","apache-beam","dataflow","missing-dependency","pip"],"backgroundTag":"missing-optional-dependency","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}