繁体   English   中英

Spring 在树莓派上使用 Jython 启动应用程序

[英]Spring boot app with Jython on raspberry pi

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

代码:

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

错误:

ImportError: Cannot import site module and its dependencies: No module named site 确定以下属性是否正确:

  • 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 不导入站点模块

好的,我解决了这个问题。 我必须启动该属性和 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();
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM