首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Java项目中使用PythonInterpreter

如何在Java项目中使用PythonInterpreter
EN

Stack Overflow用户
提问于 2020-04-11 20:59:40
回答 1查看 575关注 0票数 0

我尝试在Java中使用PythonInterpreter,但是我不能在Intellij中导入org.python.util.PythonInterpreter包。所以下面的代码不能编译:

代码语言:javascript
复制
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无法识别这个库。对我有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2020-04-13 19:55:51

确保您已将Jython正确安装到项目中。

  • 应从page下载jar文件。在您的情况下,我建议使用Jython Standalone选项。
  • 根据官方的JetBrains
  • 将jar文件添加为库

如果项目配置一切正常,但问题仍然存在,您可以尝试执行以下操作:

  • File | Invalidate Caches / Restart...
  • Close IDE。
  • 根据以下命令从现有源中删除project.
  • Remove/Rename guide.
  • Import IntelliJ IDEA缓存文件中的所有.idea文件。(File | New | Project from Existing Sources...)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61157199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档