I use the jython to call python script (use the 3rd lib pykriging) in java. But I get ImportError in java console. I had tried many methods but none works. My code is like this:
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");
}
Perhaps there is no way to work it,because 'pykriging' depends on 'numpy',but this is no good way to use numpy in jython. Using NumPy and Cpython with Jython
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.