MCPcopy Index your code
hub / github.com/go-python/gopy / getPythonVersion

Function getPythonVersion

python.go:17–37  ·  view source on GitHub ↗

getPythonVersion returns the python version available on this machine

(vm string)

Source from the content-addressed store, hash-verified

15
16// getPythonVersion returns the python version available on this machine
17func getPythonVersion(vm string) (int, error) {
18 py, err := exec.LookPath(vm)
19 if err != nil {
20 return 0, fmt.Errorf(
21 "gopy: could not locate 'python' executable (err: %v)",
22 err,
23 )
24 }
25
26 out, err := exec.Command(py, "-c", "import sys; print(sys.version_info.major)").Output()
27 if err != nil {
28 return 0, errors.Wrapf(err, "gopy: error retrieving python version")
29 }
30
31 vers, err := strconv.Atoi(strings.TrimSpace(string(out)))
32 if err != nil {
33 return 0, errors.Wrapf(err, "gopy: error retrieving python version")
34 }
35
36 return vers, nil
37}

Callers 1

genPkgFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected