首页 > 代码库 > eclipse中使用jython

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();

 

eclipse中使用jython