experimental macOS/Linux support

This commit is contained in:
josc146 2023-05-27 14:40:59 +08:00
parent 2431ff68e6
commit 2ca8f5eba9
2 changed files with 27 additions and 14 deletions

View File

@ -3,6 +3,7 @@ package backend_golang
import (
"errors"
"os/exec"
"runtime"
"strconv"
)
@ -39,6 +40,9 @@ func (a *App) InstallPyDep(cnMirror bool) (string, error) {
if err != nil {
return "", err
}
if runtime.GOOS == "windows" {
ChangeFileLine("./py310/python310._pth", 3, "Lib\\site-packages")
}
if cnMirror {
_, err = Cmd(python, "./backend-python/get-pip.py", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple")
} else {
@ -47,7 +51,6 @@ func (a *App) InstallPyDep(cnMirror bool) (string, error) {
if err != nil {
return "", err
}
ChangeFileLine("./py310/python310._pth", 3, "Lib\\site-packages")
_, err = Cmd(python, "-m", "pip", "install", "torch==1.13.1", "torchvision==0.14.1", "torchaudio==0.13.1", "--index-url", "https://download.pytorch.org/whl/cu117")
if err != nil {
return "", err

View File

@ -13,22 +13,32 @@ import (
)
func Cmd(args ...string) (string, error) {
_, err := os.Stat("cmd-helper.bat")
if err != nil {
if err := os.WriteFile("./cmd-helper.bat", []byte("start %*"), 0644); err != nil {
if runtime.GOOS == "windows" {
_, err := os.Stat("cmd-helper.bat")
if err != nil {
if err := os.WriteFile("./cmd-helper.bat", []byte("start %*"), 0644); err != nil {
return "", err
}
}
cmdHelper, err := filepath.Abs("./cmd-helper")
if err != nil {
return "", err
}
cmd := exec.Command(cmdHelper, args...)
out, err := cmd.CombinedOutput()
if err != nil {
return "", err
}
return string(out), nil
} else {
cmd := exec.Command(args[0], args[1:]...)
err := cmd.Start()
if err != nil {
return "", err
}
cmd.Wait()
return "", nil
}
cmdHelper, err := filepath.Abs("./cmd-helper")
if err != nil {
return "", err
}
cmd := exec.Command(cmdHelper, args...)
out, err := cmd.CombinedOutput()
if err != nil {
return "", err
}
return string(out), nil
}
func GetPython() (string, error) {