{"record":{"id":"175e4ba81db90f6f","repo":"apache/beam","slug":"profiling-uncompiled-code-to-compile-beam-run-pip-install","errorCode":null,"errorMessage":"Profiling uncompiled code.\nTo compile beam, run 'pip install Cython; python setup.py build_ext --inplace'","messagePattern":"Profiling uncompiled code\\.\nTo compile beam, run 'pip install Cython; python setup\\.py build_ext --inplace'","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/tools/utils.py","lineNumber":44,"sourceCode":"import time\nfrom typing import Callable\nfrom typing import NamedTuple\n\nimport numpy\n\nBenchmarkFn = Callable[[], None]\nBenchmarkFactoryFn = Callable[[int], BenchmarkFn]\n\n\ndef check_compiled(module):\n  \"\"\"Check whether given module has been compiled.\n  Args:\n    module: string, module name\n  \"\"\"\n  check_module = importlib.import_module(module)\n  ext = os.path.splitext(check_module.__file__)[-1]\n  if ext in ('.py', '.pyc'):\n    raise RuntimeError(\n        \"Profiling uncompiled code.\\n\"\n        \"To compile beam, run \"\n        \"'pip install Cython; python setup.py build_ext --inplace'\")\n\n\nclass BenchmarkConfig(NamedTuple):\n  \"\"\"\n  Attributes:\n    benchmark: a callable that takes an int argument - benchmark size,\n      and returns a callable. A returned callable must run the code being\n      benchmarked on an input of specified size.\n\n      For example, one can implement a benchmark as:\n\n      class MyBenchmark(object):\n        def __init__(self, size):\n          [do necessary initialization]\n        def __call__(self):","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/tools/utils.py#L26-L62","documentation":"RuntimeError raised by `check_compiled` in apache_beam.tools.utils when the imported Beam module (e.g. a Cython-optimized module used in benchmarks) is a pure-Python `.py`/`.pyc` file rather than a compiled extension. Beam profiling tools require the compiled build for meaningful performance numbers.","triggerScenarios":"Running Beam benchmark/profiling tools (`apache_beam.tools.*`) with a pip-installed or un-built source checkout where Cython extensions were never compiled.","commonSituations":"Profiling from a source clone without running `setup.py build_ext --inplace`; installing a pure-Python wheel; a dev environment missing Cython so extensions were skipped.","solutions":["Run `pip install Cython; python setup.py build_ext --inplace` in the Beam source root, then re-run the profiler.","Alternatively install a compiled Beam distribution (`pip install apache-beam`) if profiling against a release.","Verify the module file extension is no longer `.py`/`.pyc` before profiling."],"exampleFix":"// before\npip install apache-beam  # pure-python, no compiled extensions\n// after\npip install Cython\npython setup.py build_ext --inplace","handlingStrategy":"try-catch","validationCode":"import importlib, os\nmod = importlib.import_module(module)\nif os.path.splitext(mod.__file__)[-1] in ('.py', '.pyc'):\n    raise SystemExit('Beam not compiled: run pip install Cython; python setup.py build_ext --inplace')","typeGuard":null,"tryCatchPattern":"try:\n    run_benchmark()\nexcept RuntimeError as e:\n    if 'uncompiled code' in str(e):\n        os.system('pip install Cython && python setup.py build_ext --inplace')","preventionTips":["Build Cython extensions after every fresh source checkout","Use release wheels for profiling when source builds aren't needed","Check module file extension before benchmarking"],"tags":["apache-beam","profiling","cython","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"}