简体   繁体   中英

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

I want to use ProcessBuilder to execute a python script. I can execute this script with the command "python3 myscript.py" without any problem. But When I use ProcessBuilder in java, I get an error from my script :

import numpyImportError: No module named 'numpy'

numpy is the module that I want to use, but I can't find it. This is the way I call my script :

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

You need to specify your python path:

run in your terminal: "which python3"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM