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

  1. Verify the interpreter runs: `python -c "import sys; print(sys.executable)"` manually
  2. Fix or recreate the broken virtualenv: delete it and run the toolchain's install (e.g. `poetry install`, `uv sync`, `python -m venv .venv`)
  3. 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

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


AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31). Data as JSON: /api/errors/bf0f9b18f328063d. Report an issue: GitHub.