Java,python 脚本的 ProcessBuilder,带有 python 模块 (numpy)

Java, ProcessBuilder for python script with python module (numpy)

我想使用 ProcessBuilder 执行 python 脚本。我可以毫无问题地使用命令 "python3 myscript.py" 执行此脚本。但是当我在 java 中使用 ProcessBuilder 时,我的脚本出现错误:

import numpyImportError: No module named 'numpy'

numpy 是我想用的模块,但是找不到。 这是我调用脚本的方式:

ProcessBuilder builder = new ProcessBuilder("python3","main.py","-rd ",selectedFile.getAbsolutePath());
builder.redirectErrorStream(true);
Process process = builder.start();

您需要指定您的 python 路径:

运行 在您的终端中:"which python3"

ProcessBuilder builder = new ProcessBuilder("your/python/path/python3","main.py","-rd ",selectedFile.getAbsolutePath());