【发布时间】:2016-11-12 13:51:02
【问题描述】:
我使用 jython 在 java 中调用 python 脚本(使用 3rd 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");
}
【问题讨论】: