我正在Java中通过在ProcessBuilder方法中提及Python脚本名称来从Java调用Python脚本。
下面是Java代码的代码段:
String[] commandToProcessDocument = { "/usr/bin/python", "uploadDataMySql.py"};
ProcessBuilder pb = new ProcessBuilder(commandToProcessDocument);
pb.directory(new File("/opt/python_scripts/uploadDataMySql"));
Process p = pb.start();
以下是python脚本的代码段:
import pandas as pd
print("Welcome To Python")
df = pd.read_csv("/opt/tomcat8/webapps/aaa/dashboards/test1.csv")
print("came after reading")
我已经在Linux机器上安装了pandas,当我在linux终端中执行此python脚本时,我能够看到所有打印语句,但是当我尝试从Java代码执行相同的python脚本时,它失败了。 / p>
当我从python脚本注释此行时,然后从java代码成功执行python脚本:
#import pandas as pd
print("Welcome To Python")
#df = pd.read_csv("/opt/tomcat8/webapps/aaa/dashboards/test1.csv")
print("came after reading")
请在这里帮助我