{"record":{"id":"2d1d2ec0bcd49846","repo":"apache/beam","slug":"could-not-find-s-in-s","errorCode":null,"errorMessage":"Could not find %s in %s","messagePattern":"Could not find (.+?) in (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/gen_protos.py","lineNumber":311,"sourceCode":"\n\ndef _find_protoc_gen_mypy():\n  # NOTE: this shouldn't be necessary if the virtualenv's environment\n  #  is passed to tasks below it, since protoc will search the PATH itself\n  fname = 'protoc-gen-mypy'\n  if platform.system() == 'Windows':\n    fname += \".exe\"\n\n  pathstr = os.environ.get('PATH')\n  search_paths = pathstr.split(os.pathsep) if pathstr else []\n  # should typically be installed into the venv's bin dir\n  search_paths.insert(0, os.path.dirname(sys.executable))\n  for path in search_paths:\n    fullpath = os.path.join(path, fname)\n    if os.path.exists(fullpath):\n      LOG.info('Found protoc_gen_mypy at %s' % fullpath)\n      return fullpath\n  raise RuntimeError(\n      \"Could not find %s in %s\" % (fname, ', '.join(search_paths)))\n\n\ndef find_by_ext(root_dir, ext):\n  for root, _, files in os.walk(root_dir):\n    for file in files:\n      if file.endswith(ext):\n        yield clean_path(os.path.join(root, file))\n\ndef build_relative_import(root_path, import_path, start_file_path):\n  tail_path = import_path.replace('.', os.path.sep)\n  source_path = os.path.join(root_path, tail_path)\n\n  is_module = os.path.isfile(source_path + '.py')\n  if is_module:\n    source_path = os.path.dirname(source_path)\n\n  rel_path = os.path.relpath(","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/gen_protos.py#L293-L329","documentation":"_find_protoc_gen_mypy locates the protoc-gen-mypy executable by scanning search paths (including the directory of the running Python interpreter). If the binary is absent from every path, generation stops with RuntimeError 'Could not find <fname> in <paths>'.","triggerScenarios":"Running generate_proto_files when the mypy-protobuf plugin executable (protoc-gen-mypy) is not installed or is not on the searched PATH / venv bin directory.","commonSituations":"Building Beam in a fresh checkout or CI container where the dev extra with mypy-protobuf was not installed; using a venv without dev dependencies.","solutions":["Install the plugin: pip install mypy-protobuf (into the same environment as the interpreter running gen_protos.py).","Ensure the venv's bin directory is on PATH or that sys.executable's directory contains the binary.","Verify with `which protoc-gen-mypy` and re-run generation."],"exampleFix":"// before\npython gen_protos.py\n// after\npip install mypy-protobuf && python gen_protos.py","handlingStrategy":"validation","validationCode":"import shutil\nassert shutil.which('protoc-gen-mypy') or __import__('os').path.exists(\n    __import__('os').path.join(__import__('sys').prefix, 'bin', 'protoc-gen-mypy'))","typeGuard":"def protoc_gen_mypy_available():\n    import os, sys\n    paths = [os.path.dirname(sys.executable)] + os.environ.get('PATH', '').split(os.pathsep)\n    return any(os.path.exists(os.path.join(p, 'protoc-gen-mypy')) for p in paths)","tryCatchPattern":"try:\n    generate_proto_files()\nexcept RuntimeError as e:\n    if 'Could not find protoc-gen-mypy' in str(e):\n        subprocess.run(['pip', 'install', 'mypy-protobuf'], check=True)","preventionTips":["Always install Beam dev extras (pip install -e '.[dev]') before generating protos.","Verify protoc-gen-mypy exists in the venv bin directory in CI setup steps.","Keep mypy-protobuf pinned alongside protobuf."],"tags":["protobuf","build","missing-dependency","code-generation"],"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"}