apache/beam · error · RuntimeError

Could not find in

Error message

Could not find %s in %s

What it means

_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>'.

Solutions

  1. Install the plugin: pip install mypy-protobuf (into the same environment as the interpreter running gen_protos.py).
  2. Ensure the venv's bin directory is on PATH or that sys.executable's directory contains the binary.
  3. Verify with `which protoc-gen-mypy` and re-run generation.

Example fix

// before
python gen_protos.py
// after
pip install mypy-protobuf && python gen_protos.py
Defensive patterns

Strategy: validation

Validate before calling

import shutil
assert shutil.which('protoc-gen-mypy') or __import__('os').path.exists(
    __import__('os').path.join(__import__('sys').prefix, 'bin', 'protoc-gen-mypy'))

Type guard

def protoc_gen_mypy_available():
    import os, sys
    paths = [os.path.dirname(sys.executable)] + os.environ.get('PATH', '').split(os.pathsep)
    return any(os.path.exists(os.path.join(p, 'protoc-gen-mypy')) for p in paths)

Try / catch

try:
    generate_proto_files()
except RuntimeError as e:
    if 'Could not find protoc-gen-mypy' in str(e):
        subprocess.run(['pip', 'install', 'mypy-protobuf'], check=True)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

Thrown at sdks/python/gen_protos.py:311


def _find_protoc_gen_mypy():
  # NOTE: this shouldn't be necessary if the virtualenv's environment
  #  is passed to tasks below it, since protoc will search the PATH itself
  fname = 'protoc-gen-mypy'
  if platform.system() == 'Windows':
    fname += ".exe"

  pathstr = os.environ.get('PATH')
  search_paths = pathstr.split(os.pathsep) if pathstr else []
  # should typically be installed into the venv's bin dir
  search_paths.insert(0, os.path.dirname(sys.executable))
  for path in search_paths:
    fullpath = os.path.join(path, fname)
    if os.path.exists(fullpath):
      LOG.info('Found protoc_gen_mypy at %s' % fullpath)
      return fullpath
  raise RuntimeError(
      "Could not find %s in %s" % (fname, ', '.join(search_paths)))


def find_by_ext(root_dir, ext):
  for root, _, files in os.walk(root_dir):
    for file in files:
      if file.endswith(ext):
        yield clean_path(os.path.join(root, file))

def build_relative_import(root_path, import_path, start_file_path):
  tail_path = import_path.replace('.', os.path.sep)
  source_path = os.path.join(root_path, tail_path)

  is_module = os.path.isfile(source_path + '.py')
  if is_module:
    source_path = os.path.dirname(source_path)

  rel_path = os.path.relpath(

View on GitHub (pinned to 12126d8942)