java用runtime调用python程序报错
String executer = "E:\\anaconda\\envs\\pytorch\\python";
String file_path3 = "C:\\Users\\asus190611tan\\Desktop\\yolov5pro\\1.py";
String[] command_line = new String[] {executer, file_path1};
try {
Process process = Runtime.getRuntime().exec(command_line);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK"));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
// java代码中的 process.waitFor() 返回值(和我们通常意义上见到的0与1定义正好相反)
// 返回值为0 - 表示调用python脚本成功;
// 返回值为1 - 表示调用python脚本失败。
int re = process.waitFor();
System.out.println("调用 python 脚本是否成功:" + re);
} catch (IOException e1) {
e1.printStackTrace();
} catch (InterruptedException e2) {
e2.printStackTrace();
}
网上查了,runtime函数是在cmd里面跑,于是我去cmd里面运行了一下
C:\Users\asus190611tan>E:\anaconda\envs\pytorch\python C:\Users\asus190611tan\Desktop\yolov5pro\track.py
Traceback (most recent call last):
File "C:\Users\asus190611tan\Desktop\yolov5pro\track.py", line 303, in <module>
detect(args)
File "C:\Users\asus190611tan\Desktop\yolov5pro\track.py", line 103, in detect
cfg.merge_from_file(opt.config_deepsort)
File "C:\Users\asus190611tan\Desktop\yolov5pro\deep_sort_pytorch\utils\parser.py", line 24, in merge_from_file
with open(config_file, 'r') as fo:
FileNotFoundError: [Errno 2] No such file or directory: 'deep_sort_pytorch/configs/deep_sort.yaml'
报错文件
检测了一下文件路径是对的