【问题标题】:Install Jython to use PythonInterpreter安装 Jython 以使用 PythonInterpreter
【发布时间】:2021-03-13 07:28:10
【问题描述】:

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

IntelliJ Picture

所选目录不是 JDK 的有效主目录。

最后,我想使用 PythonInterpreter,

https://stackoverflow.com/a/8899042/15358601

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);

【问题讨论】:

    标签: java python intellij-idea jython


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-12
      • 1970-01-01
      • 2012-04-10
      • 2012-07-28
      • 2017-11-11
      • 1970-01-01
      相关资源
      最近更新 更多