{"record":{"id":"bf0f9b18f328063d","repo":"pulumi/pulumi","slug":"failed-to-get-python-executable-path-w","errorCode":null,"errorMessage":"failed to get python executable path: %w","messagePattern":"failed to get python executable path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/python/toolchain/toolchain.go","lineNumber":294,"sourceCode":"\t}\n\tparentDir := filepath.Dir(currentDir)\n\tif currentDir == parentDir {\n\t\t// Reached the root directory, file not found\n\t\treturn \"\", os.ErrNotExist\n\t}\n\treturn searchup(parentDir, fileToFind)\n}\n\nfunc getPythonExecutablePath(ctx context.Context,\n\tcommandFunc func(context.Context, ...string) (*exec.Cmd, error),\n) (string, error) {\n\tcmd, err := commandFunc(ctx, \"-c\", \"import sys; print(sys.executable)\")\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tout, err := cmd.Output()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get python executable path: %w\", err)\n\t}\n\treturn strings.TrimSpace(string(out)), nil\n}\n\nfunc ParsePythonVersion(versionString string) (semver.Version, error) {\n\tversionString = strings.TrimSpace(versionString)\n\tversionString = strings.TrimPrefix(versionString, \"Python \")\n\n\tre := regexp.MustCompile(`^(\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:(a|b|rc|dev)(\\d+))?`)\n\tmatches := re.FindStringSubmatch(versionString)\n\tif len(matches) < 3 {\n\t\treturn semver.Version{}, fmt.Errorf(\"invalid Python version format: %q\", versionString)\n\t}\n\n\tmajor, minor := matches[1], matches[2]\n\tpatch := matches[3]\n\tif patch == \"\" {\n\t\tpatch = \"0\"","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/python/toolchain/toolchain.go#L276-L312","documentation":"The library asks the interpreter for its own path by running `python -c \"import sys; print(sys.executable)\"` and capturing output. If the command fails to run or exits non-zero (interpreter missing, broken venv, crash), the error is wrapped here.","triggerScenarios":"Executing the version-check command against a Python binary that does not exist on PATH, a virtualenv whose symlinked python is broken, or one that exits with an error (corrupted stdlib, missing import machinery).","commonSituations":"Deleted/renamed venv directory leaving dangling python symlinks; `python` not installed or only `python3` present; PATH pointing at a Windows Store stub; quarantine/security software blocking exec.","solutions":["Verify the interpreter runs: `python -c \"import sys; print(sys.executable)\"` manually","Fix or recreate the broken virtualenv: delete it and run the toolchain's install (e.g. `poetry install`, `uv sync`, `python -m venv .venv`)","Set `PULUMI_PYTHON_CMD` / PATH to a working interpreter (e.g. python3)"],"exampleFix":"// before\n.venv/bin/python -> /opt/py3.9/bin/python3 (deleted)\n// after\nrm -rf .venv && python3 -m venv .venv && . .venv/bin/activate","handlingStrategy":"retry","validationCode":"cmd := exec.Command(pythonCmd, \"-c\", \"import sys; print(sys.executable)\")\nif err := cmd.Run(); err != nil {\n    return fmt.Errorf(\"python interpreter %q is not runnable\", pythonCmd)\n}","typeGuard":null,"tryCatchPattern":"path, err := getPythonExecutablePath(ctx)\nif err != nil {\n    // recreate the venv once, then retry\n    _ = recreateVirtualenv()\n    path, err = getPythonExecutablePath(ctx)\n    if err != nil { return err }\n}","preventionTips":["Point PATH/PULUMI_PYTHON_CMD at a real interpreter, not stubs","Recreate virtualenvs after upgrading or moving Python installations","Smoke-test `python -c 'import sys'` in CI before pulumi runs"],"tags":["python","interpreter","subprocess"],"backgroundTag":"python-executable-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}