public class PyInterpreter {
PythonInterpreter interpreter = null;
public PyInterpreter() {
PythonInterpreter.initialize(System.getProperties(), System.getProperties(), new String[0]);
this.interpreter = new PythonInterpreter();
}
void execfile(final String fileName){
this.interpreter.execfile(fileName);
}
PyInstance createClass(final String className, final String opts)
{
return (PyInstance) this.interpreter.eval(className + "("+ opts+ ")");
}
public static void main(String args[]){
PyInterpreter py = new PyInterpreter();
py.execfile("hello.py");
PyInstance hello = py.createClass("Hello", "None");
hello.invoke("run");
}
}
это проект maven, поэтому я добавил зависимости jython (2.7.0).когда я пытаюсь выполнить метод main, он показывает:
Исключение в потоке "main" ImportError: Невозможно импортировать модуль сайта и его зависимости: нет модуля с именем site Определите, правильны ли следующие атрибуты: * sys.path:['C: \ Users \ narendrar \ .m2 \ repository \ org \ python \ jython \ 2.7.0 \ Lib', ' classpath ', ' pyclasspath /'] Этот атрибутможет включать в себя неправильные каталоги, такие как из CPython * sys.prefix: C: \ Users \ narendrar.m2 \ repository \ org \ python \ jython \ 2.7.0 Этот атрибут устанавливается системным свойством python.home, хотя ончасто может быть автоматически определено местоположением jar-файла Jython
PS - я скопировал этот код из самого stackoverflow для тестирования.