Browse Source

Merge branch 'feature/python_0122' into debug

hsun 1 month ago
parent
commit
775ca96250
3 changed files with 13 additions and 4 deletions
  1. 1 1
      services/data/stl/stl.go
  2. 2 3
      services/smart_report.go
  3. 10 0
      utils/config.go

+ 1 - 1
services/data/stl/stl.go

@@ -601,7 +601,7 @@ print(output)
 
 	pythonCode = fmt.Sprintf(pythonCode, path, period, seasonal, trend, fraction, seasonalDeg, trendDeg, lowPassDeg, robustStr, toPath)
 	utils.FileLog.Info("stl exec python code:%s", pythonCode)
-	cmd := exec.Command(`python3`, "-c", pythonCode)
+	cmd := exec.Command(utils.CommandPython, "-c", pythonCode)
 	output, err := cmd.CombinedOutput()
 	if err != nil {
 		utils.FileLog.Info(`execStlPythonCode error:%s, input: path:%s, toPath:%s, period:%d, seasonal:%d, trend:%d, trendDeg:%d, seasonalDeg:%d, lowPassDeg:%d, fraction:%g, robust:%s, output:%s`, err.Error(), path, toPath, period, seasonal, trend, trendDeg, seasonalDeg, lowPassDeg, fraction, robustStr, string(output))

+ 2 - 3
services/smart_report.go

@@ -187,7 +187,7 @@ finally:
 
 	pyCode = fmt.Sprintf(pyCode, utils.ChromePath, width, reportUrl, width, filePath)
 	utils.FileLog.Info("pdf pyCode: \n" + pyCode)
-	cmd := exec.Command("python3", "-c", pyCode)
+	cmd := exec.Command(utils.CommandPython, "-c", pyCode)
 	output, e := cmd.CombinedOutput()
 	if e != nil {
 		err = e
@@ -265,8 +265,7 @@ finally:
 
 	pyCode = fmt.Sprintf(pyCode, utils.ChromePath, width, reportUrl, filePath)
 	utils.FileLog.Info("jpeg pyCode: \n" + pyCode)
-	cmd := exec.Command("python3", "-c", pyCode)
-
+	cmd := exec.Command(utils.CommandPython, "-c", pyCode)
 	output, e := cmd.CombinedOutput()
 	if e != nil {
 		err = e

+ 10 - 0
utils/config.go

@@ -285,6 +285,10 @@ var (
 	UseMongo bool // 是否使用mongo
 )
 
+var (
+	CommandPython string // python命令
+)
+
 func init() {
 	tmpRunMode, err := web.AppConfig.String("run_mode")
 	if err != nil {
@@ -638,4 +642,10 @@ func init() {
 		}
 		ViperConfig = viper.GetViper()
 	}
+
+	CommandPython = config["command_python"]
+	if CommandPython == "" {
+		CommandPython = "python3"
+	}
+	fmt.Println(CommandPython)
 }