Reputation: 71
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");
}
Upvotes: 0
Views: 341
Reputation: 71
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
Upvotes: 1