eclipse中使用jython

通过maven配置加载这个包,目前比较稳定的是python2.7的,见

        <dependency>
              <groupId>org.python</groupId>
              <artifactId>jython</artifactId>
              <version>2.7.0</version>
        </dependency>

然后运行个例子

 PythonInterpreter pyinterp = new PythonInterpreter();
 pyinterp.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); "); 
 pyinterp.exec("print days");

然后就挂了,显示一大堆错,吓死宝宝

ImportError: Cannot import site module and its dependencies

实际上只要设置了属性就不会再出现

 Properties props = new Properties();
 props.put("python.console.encoding", "UTF-8"); 
 props.put("python.security.respectJavaAccessibility", "false"); 
 props.put("python.import.site","false");
 Properties preprops = System.getProperties();

 

posted @ 2016-09-13 21:09  唠叨阁大学士  阅读(967)  评论(0编辑  收藏  举报