使用jython,我在Java代码中使用了一个Python文件,如下所示。 软件包jython_connect;
import org.python.core.*;
import org.python.util.PythonInterpreter;
public class jython_test1 {
private static PythonInterpreter interpreter;
public static void main(String[] args) {
interpreter = new PythonInterpreter();
interpreter.execfile("test.py");
PyObject str = interpreter.eval("test(7)");
System.out.println(str);
}
}
在test.py中包括python库,例如numpy。 出现导入错误,如下所示。
ImportError:没有名为numpy的模块
我使用的是Jython 2.7.1,我运行了以下命令,但失败了。
jython -m pip install numy
如何在Java中使用Python库?