diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java index 1df388f756f0..c153847b1878 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java @@ -238,10 +238,8 @@ private String buildPythonScriptContent() throws Exception { private String buildPythonExecuteCommand(String pythonFile) { Preconditions.checkNotNull(pythonFile, "Python file cannot be null"); - String pythonHome = System.getenv(PYTHON_HOME); - if (StringUtils.isEmpty(pythonHome)) { - return DEFAULT_PYTHON_VERSION + " " + pythonFile; - } + String pythonHome = String.format("${%s}", PYTHON_HOME); + return pythonHome + " " + pythonFile; } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java index 08c5e0d8cff9..7df534217937 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java @@ -29,7 +29,7 @@ public void buildPythonExecuteCommand() throws Exception { String methodName = "buildPythonExecuteCommand"; String pythonFile = "test.py"; String result1 = Whitebox.invokeMethod(pythonTask, methodName, pythonFile); - Assert.assertEquals("python test.py", result1); + Assert.assertEquals("${PYTHON_HOME} test.py", result1); } private PythonTask createPythonTask() {