{"record":{"id":"19d155120ad2e119","repo":"apache/beam","slug":"protobuf-files-are-not-generated-please-generate-pb2-files","errorCode":null,"errorMessage":"protobuf files are not generated. Please generate pb2 files","messagePattern":"protobuf files are not generated\\. Please generate pb2 files","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/setup.py","lineNumber":247,"sourceCode":"\n\n# We must generate protos after setup_requires are installed.\ndef generate_protos_first():\n  try:\n    # Pyproject toml build happens in isolated environemnts. In those envs,\n    # gen_protos is unable to get imported. so we run a subprocess call.\n    cwd = os.path.abspath(os.path.dirname(__file__))\n    # when pip install <>.tar.gz gets called, if gen_protos.py is not available\n    # in the sdist,then the proto files would have already been generated. So we\n    # skip proto generation in that case.\n    if not os.path.exists(os.path.join(cwd, 'gen_protos.py')):\n      # make sure we already generated protos\n      pb2_files = list(\n          find_by_ext(\n              os.path.join(cwd, 'apache_beam', 'portability', 'api'),\n              '_pb2.py'))\n      if not pb2_files:\n        raise RuntimeError(\n            'protobuf files are not generated. '\n            'Please generate pb2 files')\n\n      warnings.warn('Skipping proto generation as they are already generated.')\n      return\n    out = subprocess.run(\n        [sys.executable, os.path.join(cwd, 'gen_protos.py'), '--no-force'],\n        capture_output=True,\n        check=True)\n    print(out.stdout)\n  except subprocess.CalledProcessError as err:\n    raise RuntimeError('Could not generate protos due to error: %s', err.stderr)\n\n\ndef copy_tests_from_docs():\n  python_root = os.path.abspath(os.path.dirname(__file__))\n  docs_src = os.path.normpath(\n      os.path.join(","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/setup.py#L229-L265","documentation":"setup.py's generate_protos_first can skip running gen_protos.py when pb2 files already exist, but if the skip flag is set and no *_pb2.py files are found under apache_beam/portability/api, it raises RuntimeError. It refuses to package a SDK whose protobuf bindings were never generated.","triggerScenarios":"Building/installing apache_beam with the skip-proto-generation option while apache_beam/portability/api contains no *_pb2.py files — e.g. a clean checkout, a wiped source tree, or an sdist missing generated files.","commonSituations":"Cloning the repo and building without first running gen_protos.py; pip installing from a git checkout; CI cleaning generated artifacts between steps.","solutions":["Run `python setup.py generate_protos_first` without the skip flag, or run `python gen_protos.py` first","Verify apache_beam/portability/api contains *_pb2.py files: ls apache_beam/portability/api/*_pb2.py","Install protoc and grpcio-tools prerequisites if gen_protos.py failed silently earlier","Use the official PyPI sdist which ships pre-generated pb2 files"],"exampleFix":"# before\n$ python setup.py py_sdist --skip_proto_generation\nRuntimeError: protobuf files are not generated. Please generate pb2 files\n# after\n$ python gen_protos.py\n$ python setup.py py_sdist --skip_proto_generation","handlingStrategy":"validation","validationCode":"import glob, os\npb2 = glob.glob(os.path.join('apache_beam', 'portability', 'api', '*_pb2.py'))\nif not pb2:\n    run_gen_protos_first()  # python gen_protos.py","typeGuard":null,"tryCatchPattern":"try:\n    build_package()\nexcept RuntimeError as e:\n    if 'protobuf files are not generated' in str(e):\n        subprocess.run(['python', 'gen_protos.py'], check=True)\n        build_package()\n    else:\n        raise","preventionTips":["Run gen_protos.py after any clean checkout","Never wipe generated pb2 files in CI before packaging","Prefer released sdists over raw git installs for end use"],"tags":["python","protobuf","codegen","build"],"backgroundTag":"missing-dependency","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}