{"record":{"id":"e5a7d3100a7678f2","repo":"xtekky/gpt4free","slug":"ensurepip-failed-exit-d-w","errorCode":null,"errorMessage":"ensurepip failed (exit %d): %w","messagePattern":"ensurepip failed \\(exit (.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"g4f-go/runtime.go","lineNumber":148,"sourceCode":"\t}\n\tif err := os.WriteFile(stamp, []byte(\"g4f installed\"), 0o644); err != nil {\n\t\treturn err\n\t}\n\tfmt.Printf(\"gpt4free installed in %.1fs\\n\", time.Since(start).Seconds())\n\treturn nil\n}\n\n// ensurePip makes `python -m pip` available in the downloaded runtime.\n// pbs installs ship ensurepip but no standalone pip; bootstrap once.\nfunc ensurePip(binDir, exe string) error {\n\tcode, err := runPython(noSignalCtx(), exe, []string{\"-c\", \"import pip\"}, pipEnv(binDir)...)\n\tif err == nil && code == 0 {\n\t\treturn nil\n\t}\n\tfmt.Println(\"  bootstrapping pip (ensurepip)...\")\n\tcode, err = runPython(noSignalCtx(), exe, []string{\"-m\", \"ensurepip\", \"--upgrade\"}, pipEnv(binDir)...)\n\tif err != nil || code != 0 {\n\t\treturn fmt.Errorf(\"ensurepip failed (exit %d): %w\", code, err)\n\t}\n\treturn nil\n}\n\n// pipEnv restricts pip to the downloaded runtime so installs never touch the\n// host Python. pbs installs are a full layout: lib/pythonX.Y/site-packages\n// (unix) or Lib/site-packages (windows) inside the interpreter home.\nfunc pipEnv(binDir string) []string {\n\thome := pythonHome(binDir)\n\tlib := filepath.Join(home, \"Lib\", \"site-packages\")\n\tif runtime.GOOS != \"windows\" {\n\t\tlib = filepath.Join(home, \"lib\", \"python3.14\", \"site-packages\")\n\t}\n\treturn []string{\n\t\t\"PYTHONHOME=\" + home,\n\t\t\"PYTHONNOUSERSITE=1\",\n\t\t\"PYTHONDONTWRITEBYTECODE=1\",\n\t\t\"PYTHONUTF8=1\",","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f-go/runtime.go#L130-L166","documentation":"Error \"ensurepip failed (exit %d): %w\" thrown in xtekky/gpt4free.","triggerScenarios":"Thrown at g4f-go/runtime.go:148 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-extract the python runtime (delete the runtime dir and re-run) and retry ensurepip."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}