【问题标题】:Spring boot app with Jython on raspberry pi在树莓派上使用 Jython 的 Spring Boot 应用程序
【发布时间】:2021-01-19 18:52:46
【问题描述】:

我正在尝试在树莓派上的 Spring Boot 项目中使用 jython。我有一个问题,因为当我在 Windows 上运行它时它可以工作,但在树莓派(系统 raspbian)上不起作用。它在 new PythonInterpreter() 上崩溃了。

代码:

try {
        PythonInterpreter pyInterp = new PythonInterpreter();
        pyInterp.exec("print('Hello Python World!')");
    } catch (Exception e) {
        e.printStackTrace();
    }

错误:

ImportError:无法导入站点模块及其依赖项:没有名为站点的模块 判断以下属性是否正确:

  • sys.path: [/home/pi/Dysk/raspdemo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/Lib, classpath, pyclasspath>] 此属性可能包含错误的目录,例如来自 CPython
  • sys.prefix: /home/pi/Dysk/raspdemo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib 该属性由系统属性 python.home 设置,尽管它可以 通常由 Jython jar 文件的位置自动确定

您可以使用 -S 选项或 python.import.site=false 来不导入站点模块

【问题讨论】:

  • 请提供完整的堆栈跟踪,这可能会有所帮助

标签: java spring-boot raspberry-pi jython


【解决方案1】:

好的,我解决了这个问题。我必须启动该属性,以及 props.put("python.import.site", "false");运行参数很重要。

    try {
        Properties props = new Properties();
        props.put("python.home", "/home/pi/Dysk/jython-standalone-2.7.1.jar");
        props.put("python.console.encoding", "UTF-8");
        props.put("python.security.respectJavaAccessibility", "false");
        props.put("python.import.site", "false");
        Properties preprops = System.getProperties();
        PythonInterpreter.initialize(preprops, props, new String[0]);

        PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.exec("print('Hello Python World!')");
    } catch (Exception e) {
        e.printStackTrace();
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-05
    • 2021-12-07
    • 2016-10-25
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    相关资源
    最近更新 更多