安装 Jython 以使用 PythonInterpreter

Install Jython to use PythonInterpreter

我正在尝试将 Jython SDK 安装到 IntelliJ Java 程序中。如何才能做到这一点?我在这里默认安装了 Jython:C:\jython2.7.2 并为 Windows 安装了 Python 。选择此目录或其 bin,出现此错误

IntelliJ Picture

The selected directory is not a valid home for JDK.

最终,我想利用Python解释器,

PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("import sys\nsys.path.append('pathToModules if they are not there by default')\nimport yourModule");
// execute a function that takes a string and returns a string
PyObject someFunc = interpreter.get("funcName");
PyObject result = someFunc.__call__(new PyString("Test!"));
String realResult = (String) result.__tojava__(String.class);

您应该选择 JDK 主目录,而不是 jython 主目录。示例:C:\Program Files\Java\jdk1.8.0_112