{"record":{"id":"e036bfec5e51da2d","repo":"bazelbuild/bazel","slug":"python-coverage-tool-r-not-found-try-running-wit","errorCode":null,"errorMessage":"Python coverage tool %r not found. Try running with VERBOSE_COVERAGE=1 to collect more information.","messagePattern":"Python coverage tool %r not found\\. Try running with VERBOSE_COVERAGE=1 to collect more information\\.","errorType":"exception","errorClass":"EnvironmentError","httpStatus":null,"severity":"error","filePath":"tools/python/python_bootstrap_template.txt","lineNumber":517,"sourceCode":"\n  program = python_program = FindPythonBinary(module_space)\n  if python_program is None:\n    raise AssertionError('Could not find python binary: ' + PYTHON_BINARY)\n\n  # COVERAGE_DIR is set if coverage is enabled and instrumentation is configured\n  # for something, though it could be another program executing this one or\n  # one executed by this one (e.g. an extension module).\n  if os.environ.get('COVERAGE_DIR'):\n    cov_tool = FindCoverageEntryPoint(module_space)\n    if cov_tool is None:\n      PrintVerboseCoverage('Coverage was enabled, but python coverage tool was not configured.')\n    else:\n      # Inhibit infinite recursion:\n      if 'PYTHON_COVERAGE' in os.environ:\n        del os.environ['PYTHON_COVERAGE']\n\n      if not os.path.exists(cov_tool):\n        raise EnvironmentError(\n          'Python coverage tool %r not found. '\n          'Try running with VERBOSE_COVERAGE=1 to collect more information.'\n          % cov_tool\n        )\n\n      # coverage library expects sys.path[0] to contain the library, and replaces\n      # it with the directory of the program it starts. Our actual sys.path[0] is\n      # the runfiles directory, which must not be replaced.\n      # CoverageScript.do_execute() undoes this sys.path[0] setting.\n      #\n      # Update sys.path such that python finds the coverage package. The coverage\n      # entry point is coverage.coverage_main, so we need to do twice the dirname.\n      python_path_entries = new_env['PYTHONPATH'].split(os.pathsep)\n      python_path_entries.append(os.path.dirname(os.path.dirname(cov_tool)))\n      new_env['PYTHONPATH'] = os.pathsep.join(Deduplicate(python_path_entries))\n  else:\n    cov_tool = None\n","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/tools/python/python_bootstrap_template.txt#L499-L535","documentation":"Raised by the Python launcher when coverage is enabled (COVERAGE_DIR set), a coverage entry point was resolved via runfiles, but that resolved path does not exist on disk (EnvironmentError/OSError). The message suggests VERBOSE_COVERAGE=1 to trace how the entry point was found.","triggerScenarios":"COVERAGE_DIR is set in the environment and the configured python coverage tool's runfiles path resolves to a location with no actual file — stale runfiles, a coverage tool target not built, or a manually set PYTHON_COVERAGE pointing at a missing script.","commonSituations":"Running bazel coverage where the coverage tool target was not included in the runfiles; leftover COVERAGE_DIR from a previous CI step; mixing python2/python3 coverage entry points after an interpreter migration.","solutions":["Rerun with VERBOSE_COVERAGE=1 to see which entry point path failed to resolve.","Ensure the python coverage tool target is properly configured and present in the binary's runfiles (correct coverage plugin/toolchain registration).","Unset COVERAGE_DIR if coverage was not intended for this run."],"exampleFix":"# before\nCOVERAGE_DIR=/tmp/cov ./my_binary  # coverage tool absent from runfiles\n\n# after\nunset COVERAGE_DIR && ./my_binary  # or fix coverage tool registration, then:\n# VERBOSE_COVERAGE=1 bazel coverage //my:target","handlingStrategy":"validation","validationCode":"import os\ncov = os.environ.get('PYTHON_COVERAGE')\nif os.environ.get('COVERAGE_DIR') and cov:\n    assert os.path.exists(cov), 'coverage entry point %r missing from runfiles' % cov","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register the python coverage tool in the build so its entry point lands in runfiles.","Use VERBOSE_COVERAGE=1 whenever triaging coverage startup problems.","Clear COVERAGE_DIR when coverage is not intended."],"tags":["python","coverage","bazel","bootstrap"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}