从Java调用Python(Anaconda)时出现问题 [英] Issue while calling Python(Anaconda) from Java

查看:725
本文介绍了从Java调用Python(Anaconda)时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ProcessBuilder从Java调用Python(Anaconda)代码.当我仅安装Python时,它运行良好.但是现在我删除了Python并安装了Anaconda.调用Python的代码现在无法正常工作. 出现以下错误.

I am calling Python(Anaconda) code from Java using ProcessBuilder. It was working fine when I had installed only Python. But now I have removed Python and installed Anaconda. The code to call Python is not working now. Getting the following error.

 com.api.ai.helper.MLPythonAPI callPyhonScriptToPredict
SEVERE: null
java.io.IOException: Cannot run program "python": CreateProcess error=2, The system cannot find the file specified
       at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
       at com.api.ai.helper.MLPythonAPI.callPyhonScriptToPredict(MLPythonAPI.java:66)

我正在使用python 3.6.1(anaconda3 4.4.0 64位)和以下代码来执行python

I am using python 3.6.1(anaconda3 4.4.0 64 bit) and following code to execute Python

ProcessBuilder pb = new ProcessBuilder().inheritIO().
                    command("python", "C:\\my_code\\test.py", userSays, filePath);
            Process p = pb.start();
            p.waitFor();

有人可以帮我吗?

推荐答案

我在命令方法中传递了完整的Python路径(代替了"python",现在可以正常使用了.)

I passed the complete Python path in command method(in stead of "python" and now it is working fine.

这篇关于从Java调用Python(Anaconda)时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆