improve python dependencies installation
This commit is contained in:
parent
64f0610ed7
commit
51c5696bb9
@ -2,9 +2,11 @@ package backend_golang
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *App) StartServer(python string, port int, host string) (string, error) {
|
func (a *App) StartServer(python string, port int, host string) (string, error) {
|
||||||
@ -48,6 +50,9 @@ func (a *App) InstallPyDep(python string, cnMirror bool) (string, error) {
|
|||||||
var err error
|
var err error
|
||||||
if python == "" {
|
if python == "" {
|
||||||
python, err = GetPython()
|
python, err = GetPython()
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
python = `"` + python + `"`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -55,39 +60,24 @@ func (a *App) InstallPyDep(python string, cnMirror bool) (string, error) {
|
|||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
ChangeFileLine("./py310/python310._pth", 3, "Lib\\site-packages")
|
ChangeFileLine("./py310/python310._pth", 3, "Lib\\site-packages")
|
||||||
}
|
installScript := python + " ./backend-python/get-pip.py -i https://pypi.tuna.tsinghua.edu.cn/simple\n" +
|
||||||
|
python + " -m pip install torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 --index-url https://download.pytorch.org/whl/cu117\n" +
|
||||||
if runtime.GOOS == "windows" {
|
python + " -m pip install -r ./backend-python/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple\n" +
|
||||||
if cnMirror {
|
"exit"
|
||||||
_, err = Cmd(python, "./backend-python/get-pip.py", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple")
|
if !cnMirror {
|
||||||
} else {
|
installScript = strings.Replace(installScript, " -i https://pypi.tuna.tsinghua.edu.cn/simple", "", -1)
|
||||||
_, err = Cmd(python, "./backend-python/get-pip.py")
|
installScript = strings.Replace(installScript, "requirements.txt", "requirements_versions.txt", -1)
|
||||||
}
|
}
|
||||||
|
err = os.WriteFile("./install-py-dep.bat", []byte(installScript), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
return Cmd("install-py-dep.bat")
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if cnMirror {
|
||||||
_, 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")
|
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_without_cyac.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple")
|
||||||
} else {
|
} else {
|
||||||
_, err = Cmd(python, "-m", "pip", "install", "torch", "torchvision", "torchaudio")
|
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_without_cyac.txt")
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
if cnMirror {
|
|
||||||
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple")
|
|
||||||
} else {
|
|
||||||
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_versions.txt")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if cnMirror {
|
|
||||||
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_without_cyac.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple")
|
|
||||||
} else {
|
|
||||||
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_without_cyac.txt")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
func Cmd(args ...string) (string, error) {
|
func Cmd(args ...string) (string, error) {
|
||||||
switch platform := runtime.GOOS; platform {
|
switch platform := runtime.GOOS; platform {
|
||||||
case "windows":
|
case "windows":
|
||||||
if err := os.WriteFile("./cmd-helper.bat", []byte("start /wait %*"), 0644); err != nil {
|
if err := os.WriteFile("./cmd-helper.bat", []byte("start %*"), 0644); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
cmdHelper, err := filepath.Abs("./cmd-helper")
|
cmdHelper, err := filepath.Abs("./cmd-helper")
|
||||||
@ -115,11 +115,19 @@ func GetPython() (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.New("failed to unzip python")
|
return "", errors.New("failed to unzip python")
|
||||||
} else {
|
} else {
|
||||||
return "py310/python.exe", nil
|
python, err := filepath.Abs("py310/python.exe")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return python, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return "py310/python.exe", nil
|
python, err := filepath.Abs("py310/python.exe")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return python, nil
|
||||||
}
|
}
|
||||||
case "darwin":
|
case "darwin":
|
||||||
return "python3", nil
|
return "python3", nil
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
2
main.go
2
main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ func main() {
|
|||||||
backend.CopyEmbed(cyac)
|
backend.CopyEmbed(cyac)
|
||||||
backend.CopyEmbed(cyacInfo)
|
backend.CopyEmbed(cyacInfo)
|
||||||
backend.CopyEmbed(py)
|
backend.CopyEmbed(py)
|
||||||
|
os.Mkdir("models", os.ModePerm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an instance of the app structure
|
// Create an instance of the app structure
|
||||||
|
Loading…
Reference in New Issue
Block a user