{"record":{"id":"610a736bc6b80936","repo":"apache/beam","slug":"python-bootstrap-failed-with-error-result-lastnonemptyline","errorCode":null,"errorMessage":"Python bootstrap failed with error ${result}, ${lastNonEmptyLine}","messagePattern":"Python bootstrap failed with error (.+?), (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/PythonService.java","lineNumber":123,"sourceCode":"    Process bootstrap =\n        new ProcessBuilder(bootstrapCommand).redirectError(ProcessBuilder.Redirect.INHERIT).start();\n    bootstrap.getOutputStream().close();\n    BufferedReader reader =\n        new BufferedReader(\n            new InputStreamReader(bootstrap.getInputStream(), StandardCharsets.UTF_8));\n    String lastLine = reader.readLine();\n    String lastNonEmptyLine = lastLine;\n    while (lastLine != null) {\n      LOG.info(\"{}\", lastLine);\n      if (lastLine.length() > 0) {\n        lastNonEmptyLine = lastLine;\n      }\n      lastLine = reader.readLine();\n    }\n    reader.close(); // Make SpotBugs happy.\n    int result = bootstrap.waitFor();\n    if (result != 0) {\n      throw new RuntimeException(\n          \"Python bootstrap failed with error \" + result + \", \" + lastNonEmptyLine);\n    }\n    String pythonExecutable = lastNonEmptyLine;\n    List<String> command = new ArrayList<>();\n    command.add(pythonExecutable);\n    command.add(\"-m\");\n    command.add(module);\n    command.addAll(args);\n    LOG.info(\"Starting python service with arguments {}\", command);\n    Process p =\n        new ProcessBuilder(command)\n            .redirectError(ProcessBuilder.Redirect.INHERIT)\n            .redirectOutput(ProcessBuilder.Redirect.INHERIT)\n            .start();\n    return p::destroy;\n  }\n\n  private String whichPython() {","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/PythonService.java#L105-L141","documentation":"PythonService.start first runs the Python bootstrap script to locate the interpreter and provision the environment. If that bootstrap process exits with a non-zero code, the library throws RuntimeException including the exit code and the last non-empty output line, which usually contains the underlying pip/python error.","triggerScenarios":"Bootstrap subprocess exits non-zero: broken python installation, missing pip/setuptools, network failure downloading the beam Apache Beam package, incompatible Python version, or a corrupted virtualenv created during bootstrapping.","commonSituations":"No internet access in CI so pip install fails; Python 2.7 found instead of a supported Python 3; proxy/firewall blocking PyPI; --bootstrap with a bad requirements spec.","solutions":["Read the lastNonEmptyLine in the exception message — it contains the actual bootstrap error and fix that first","Run the bootstrap manually (python -m pip install 'apache_beam[...]==<version>') to reproduce and fix the environment","Verify a supported Python 3 interpreter is on PATH and pip works (python --version, pip download test)","Check network/proxy settings if PyPI is unreachable"],"exampleFix":"// before (shell)\nexport PATH=/usr/bin:$PATH   # picks python2\n// after\nexport PATH=/usr/local/bin:$PATH  # python3.x first; or set\nPythonService.setPythonExecutable(\"/usr/bin/python3.9\");","handlingStrategy":"try-catch","validationCode":"Process p = new ProcessBuilder(\"python3\", \"--version\").start();\nif (p.waitFor() != 0) { throw new IllegalStateException(\"python3 not usable\"); }","typeGuard":null,"tryCatchPattern":"try {\n  service.start();\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Python bootstrap failed\")) {\n    // inspect embedded error line; fix env (pip/python version/network) and retry\n  }\n}","preventionTips":["Pin a supported Python 3 interpreter via PythonService.setPythonExecutable","Ensure pip and network access to PyPI in CI/containers","Run bootstrap once at deploy time and cache the prepared environment","Check the exception's embedded lastNonEmptyLine for the root cause"],"tags":["java","python","subprocess","environment","bootstrap"],"backgroundTag":"module-init-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-15T13:17:12.816Z"}