Jython+Grails 出现无法导入模块的错误解决方法
版权所有,欢迎转载,转载请注明 : SinFrancis http://mdev.cc使用Grails做前端,后台需要调用python,于是使用jython作为中转。
发现在WEB服务器中找不到需要的模块,比如os等,
于是使用了 sys.path.add("C:\\jython2.5.1\\Lib");将jython的模块导入进来即可,
也可以动态获得jython的配置,然后进行导入。
PythonInterpreter interp =new PythonInterpreter(); interp = new PythonInterpreter(null, new PySystemState()); PySystemState sys = Py.getSystemState(); sys.path.add("C:\\jython2.5.1\\Lib");//插入jython的类库 interp.exec("import sys"); interp.exec("import os"); interp.exec("os.system('python convert.py');");
页:
[1]