From d0d8804fdf2982e5ae9776bd4349755a9c425a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Va=C5=A1ek?= Date: Mon, 13 Oct 2025 20:48:42 +0200 Subject: [PATCH] fix: use python3 when python not presetn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej VaĊĦek --- pkg/functions/runner.go | 10 +++++++++- pkg/oci/python_builder.go | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/functions/runner.go b/pkg/functions/runner.go index f0dedf2bdb..aa51cdb384 100644 --- a/pkg/functions/runner.go +++ b/pkg/functions/runner.go @@ -195,7 +195,7 @@ func runPython(ctx context.Context, job *Job) (err error) { if job.verbose { fmt.Printf("python -m venv .venv\n") } - cmd := exec.CommandContext(ctx, "python", "-m", "venv", ".venv") + cmd := exec.CommandContext(ctx, pythonCmd(), "-m", "venv", ".venv") cmd.Dir = job.Dir() cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout @@ -360,3 +360,11 @@ func choosePort(iface, preferredPort string) (string, error) { } return port, nil } + +func pythonCmd() string { + _, err := exec.LookPath("python") + if err != nil { + return "python3" + } + return "python" +} diff --git a/pkg/oci/python_builder.go b/pkg/oci/python_builder.go index 8e75986b0a..4272590928 100644 --- a/pkg/oci/python_builder.go +++ b/pkg/oci/python_builder.go @@ -24,7 +24,7 @@ func (b pythonBuilder) Base(customBase string) string { if customBase != "" { return customBase } - cmd := exec.Command("python", "-V") + cmd := exec.Command(pythonCmd(), "-V") out, err := cmd.CombinedOutput() if err != nil { return defaultPythonBase @@ -61,7 +61,7 @@ func (b pythonBuilder) WriteShared(job buildJob) (layers []imageLayer, err error if job.verbose { fmt.Printf("python -m venv .venv\n") } - cmd := exec.CommandContext(job.ctx, "python", "-m", "venv", ".venv") + cmd := exec.CommandContext(job.ctx, pythonCmd(), "-m", "venv", ".venv") cmd.Dir = job.buildDir() cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout @@ -205,3 +205,11 @@ func newPythonLibTarball(job buildJob, root, target string) error { func (b pythonBuilder) WritePlatform(ctx buildJob, p v1.Platform) (layers []imageLayer, err error) { return []imageLayer{}, nil } + +func pythonCmd() string { + _, err := exec.LookPath("python") + if err != nil { + return "python3" + } + return "python" +}