[英]How to use PythonInterpreter in Java project Intellij - Jython
我嘗試在 Java 中使用 PythonInterpreter,但我無法在 Intellij 中導入 org.python.util.PythonInterpreter package。 所以下面的代碼無法編譯:
import org.python.util.PythonInterpreter;
import org.python.core.*;
public class SimpleEmbedded {
public static void main(String[] args) throws PyException {
PythonInterpreter interp = new PythonInterpreter();
System.out.println("Hello, brave new world");
interp.exec("import sys");
interp.exec("print sys");
interp.set("a", new PyInteger(42));
interp.exec("print a");
interp.exec("x = 2+2");
PyObject x = interp.get("x");
System.out.println("x: "+x);
System.out.println("Goodbye, cruel world");
}
}
我嘗試下載 jython zip 庫,但 Intellij 無法識別該庫。 對我有什么建議嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.