我使用jython在java中调用python脚本(使用第三个lib pykriging)。但我在 java 控制台中收到 ImportError 。我尝试了很多方法,但没有一个有效。 我的代码是这样的:
public static void main(String[] args) {
Properties props = new Properties();
props.put("python.home","D:\\prog\\Python27");
props.put("python.console.encoding", "UTF-8");
props.put("python.security.respectJavaAccessibility", "false"); //don't respect java accessibility, so that we can access protected members on subclasses
props.put("python.import.site","false");
Properties preprops = System.getProperties();
PySystemState.initialize(preprops, props, new String[0]);
PySystemState sys = Py.getSystemState();
sys.path.append(new PyString("D:\\prog\\Python27"));
sys.path.append(new PyString("D:\\prog\\Python27\\Lib\\site-packages"));
PythonInterpreter interp = new PythonInterpreter();
interp.execfile("pyt/example.py");
}
最佳答案
也许没有办法实现它,因为“pykriging”依赖于“numpy”,但这不是在 jython 中使用 numpy 的好方法。 Using NumPy and Cpython with Jython
关于java jython 导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38292991/