java怎么调用python_java如何调用python的依赖库

public classFirstJavaScript{

public static voidmain(String args[]) {

// Properties props = new Properties();// props.put("python.import.site", "false");// Properties preprops = System.getProperties();// PythonInterpreter.initialize(preprops, props, new String[0]);// PythonInterpreter interpreter = new PythonInterpreter();// interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");//interpreter.exec("print days[1];");// interpreter.exec("print('hello')");try{

System.out.println("start");

String[] args1=newString[]{"D:python.py","D:python.py"};

Process pr=Runtime.getRuntime().exec(args1);

BufferedReader in = newBufferedReader(newInputStreamReader(

pr.getInputStream()));

String line;

while((line = in.readLine()) != null) {

System.out.println(line);

}

in.close();

pr.waitFor();

System.out.println("end");

} catch(Exception e) {

e.printStackTrace();

}

}

public voidtest(){

System.out.println("我的第一个方法C");

}

}

import numpy as np

if __name__ == '__main__':

a = np.ones(3)

print(a)

print('java 调用有第三方库的python脚本成功')

报错:

start

Disconnected from the target VM, address: '127.0.0.1:51405', transport: 'socket'

java.io.IOException: Cannot run program "D:python.py": CreateProcess error=193, %1 不是有效的 Win32 应用程序。

at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

at java.lang.Runtime.exec(Runtime.java:620)

at java.lang.Runtime.exec(Runtime.java:485)

at com.wd.emrsearch.python.FirstJavaScript.main(FirstJavaScript.java:27)

Caused by: java.io.IOException: CreateProcess error=193, %1 不是有效的 Win32 应用程序。

at java.lang.ProcessImpl.create(Native Method)

at java.lang.ProcessImpl.(ProcessImpl.java:386)

at java.lang.ProcessImpl.start(ProcessImpl.java:137)

at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)

... 3 more

求大神指点

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值