MCPcopy Index your code
hub / github.com/celer-pkg/celer / GetSystemPythonVersion

Function GetSystemPythonVersion

buildtools/python/python.go:17–48  ·  view source on GitHub ↗

GetSystemPythonVersion detects the system python version.

()

Source from the content-addressed store, hash-verified

15
16// GetSystemPythonVersion detects the system python version.
17func 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}

Callers 1

GetDefaultPythonVersionFunction · 0.92

Calls 1

CommandMethod · 0.65

Tested by

no test coverage detected