pulumi/pulumi · error
failed to get python executable path: %w
Error message
failed to get python executable path: %w
What it means
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.
Source
Thrown at sdk/python/toolchain/toolchain.go:294
}
parentDir := filepath.Dir(currentDir)
if currentDir == parentDir {
// Reached the root directory, file not found
return "", os.ErrNotExist
}
return searchup(parentDir, fileToFind)
}
func getPythonExecutablePath(ctx context.Context,
commandFunc func(context.Context, ...string) (*exec.Cmd, error),
) (string, error) {
cmd, err := commandFunc(ctx, "-c", "import sys; print(sys.executable)")
if err != nil {
return "", err
}
out, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("failed to get python executable path: %w", err)
}
return strings.TrimSpace(string(out)), nil
}
func ParsePythonVersion(versionString string) (semver.Version, error) {
versionString = strings.TrimSpace(versionString)
versionString = strings.TrimPrefix(versionString, "Python ")
re := regexp.MustCompile(`^(\d+)\.(\d+)(?:\.(\d+))?(?:(a|b|rc|dev)(\d+))?`)
matches := re.FindStringSubmatch(versionString)
if len(matches) < 3 {
return semver.Version{}, fmt.Errorf("invalid Python version format: %q", versionString)
}
major, minor := matches[1], matches[2]
patch := matches[3]
if patch == "" {
patch = "0"View on GitHub (pinned to 793f7b2e16)
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)
Example fix
// before .venv/bin/python -> /opt/py3.9/bin/python3 (deleted) // after rm -rf .venv && python3 -m venv .venv && . .venv/bin/activate
Defensive patterns
Strategy: retry
Validate before calling
cmd := exec.Command(pythonCmd, "-c", "import sys; print(sys.executable)")
if err := cmd.Run(); err != nil {
return fmt.Errorf("python interpreter %q is not runnable", pythonCmd)
} Try / catch
path, err := getPythonExecutablePath(ctx)
if err != nil {
// recreate the venv once, then retry
_ = recreateVirtualenv()
path, err = getPythonExecutablePath(ctx)
if err != nil { return err }
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- program exited unexpectedly: %w: %s
- problem executing plugin program (could not run language exe
- calling `%s`: %w
- creating virtual environment at '%s': %w
- %s via '%s': %w
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/bf0f9b18f328063d.
Report an issue: GitHub.