GetSystemPythonVersion detects the system python version.
()
| 15 | |
| 16 | // GetSystemPythonVersion detects the system python version. |
| 17 | func GetSystemPythonVersion() string { |
| 18 | var ( |
| 19 | output []byte |
| 20 | err error |
| 21 | ) |
| 22 | |
| 23 | if runtime.GOOS == "windows" { |
| 24 | // On Windows, try python.exe or python3.exe |
| 25 | output, err = exec.Command("python", "--version").Output() |
| 26 | if err != nil { |
| 27 | output, err = exec.Command("python3", "--version").Output() |
| 28 | } |
| 29 | } else { |
| 30 | // On Unix-like systems, try python3 |
| 31 | output, err = exec.Command("python3", "--version").Output() |
| 32 | if err != nil { |
| 33 | output, err = exec.Command("python", "--version").Output() |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | if err != nil { |
| 38 | return "" |
| 39 | } |
| 40 | |
| 41 | // Parse "Python 3.11.0" -> "3.11.0" |
| 42 | versionStr := strings.TrimSpace(string(output)) |
| 43 | parts := strings.Fields(versionStr) |
| 44 | if len(parts) >= 2 { |
| 45 | return parts[1] |
| 46 | } |
| 47 | return "" |
| 48 | } |
no test coverage detected