From: Ivan P. <ipo...@ma...> - 2015-09-24 07:04:00
|
Hello, Jonn! There is no Lib inside standalone jython jar, so you should distribute it with your application. You should use the following while instantiating the Python Interpreter //I'll tell about the way to get new PySystemState later... PySystemState state.... //here you add the path to your system libraries state.path.append(new PyString(path)); new PythonInterpreter(null, state); Now about PySystemState. For version 2.5, it was ok to write just PySystemState state = new PySystemState()) But with the same code we came across 'No module named os' error in version 2.7 (it occured not always, but from time to time)! We found out that changing the code to PySystemState state = Py.getSystemState() is solving 'no module named os' issue, however, since PySystemState returned by Py.getSystemState() apparently caches the compiled byte code and there is no other way to change Python scripts 'on the fly' but restarting the whole application. So if you need to change Python modules 'on the fly', you have a problem. We posted a message here (http://sourceforge.net/p/jython/mailman/message/34413663/), but received no answer from Jython team. Please let us know if your problem is about the same thing or it is something else. Regards, Ivan Ponomarev On 23.09.2015 21:18, John Chiang wrote: > Hi, > > I am currently working on a web application which allows user to > upload/run python script in web application. I copied > jython-standalone-2.7.0.jar to WEB-INF/lib and build web application > as war file. however, I get a following error when running a python > script: > > org.python.core.PyException: null > > at org.python.core.Py.ImportError(Py.java:328) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.imp.import_first(imp.java:877) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.imp.import_module_level(imp.java:972) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.imp.importName(imp.java:1062) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.ImportFunction.__call__(__builtin__.java:1280) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.PyObject.__call__(PyObject.java:431) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.__builtin__.__import__(__builtin__.java:1232) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.imp.importOne(imp.java:1081) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.pycode._pyx18.f$0(<script>:11) ~[na:na] > > at org.python.pycode._pyx18.call_function(<script>) ~[na:na] > > at org.python.core.PyTableCode.call(PyTableCode.java:167) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.PyCode.call(PyCode.java:18) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.Py.runCode(Py.java:1386) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.Py.exec(Py.java:1430) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276) > ~[jython-standalone-2.7.0.jar!/:na] > > at > com.xactly.xsql.expression.arithmetic.ProcedureScalarOp.allocate(ProcedureScalarOp.java:92) > ~[xsql-0.9.99-SNAPSHOT.jar!/:na] > > > I found a workaround by running jython installer and setting > python.home by specifying -Dpython.home=<jython install directory> as > a JVM parameter. I think the purpose of using > jython-standalone-2.7.0.jar is to be able to run jython without > running installer. > > How do I specify jython-standalone-2.7.0.jar as python.home? I think > somehow it needs Lib directory which is inside of jar. > > > Any recommendations are appreciated. Thanks > > John > > > On Tue, Sep 22, 2015 at 3:49 PM, John Chiang > <joh...@xa... <mailto:joh...@xa...>> wrote: > > Hi, > > I am currently working on a web application which allows user to > upload/run python script in web application. I copied > jython-standalone-2.7.0.jar to WEB-INF/lib and build web > application as war file. however, I get a following error when > running a python script: > > org.python.core.PyException: null > > at org.python.core.Py.ImportError(Py.java:328) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.imp.import_first(imp.java:877) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.imp.import_module_level(imp.java:972) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.imp.importName(imp.java:1062) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.ImportFunction.__call__(__builtin__.java:1280) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.PyObject.__call__(PyObject.java:431) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.__builtin__.__import__(__builtin__.java:1232) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.imp.importOne(imp.java:1081) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.pycode._pyx18.f$0(<script>:11) ~[na:na] > > at org.python.pycode._pyx18.call_function(<script>) ~[na:na] > > at org.python.core.PyTableCode.call(PyTableCode.java:167) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.PyCode.call(PyCode.java:18) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.Py.runCode(Py.java:1386) > ~[jython-standalone-2.7.0.jar!/:na] > > at org.python.core.Py.exec(Py.java:1430) > ~[jython-standalone-2.7.0.jar!/:na] > > at > org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276) > ~[jython-standalone-2.7.0.jar!/:na] > > at > com.xactly.xsql.expression.arithmetic.ProcedureScalarOp.allocate(ProcedureScalarOp.java:92) > ~[xsql-0.9.99-SNAPSHOT.jar!/:na] > > > I found a workaround by running jython installer and setting > python.home by specifying -Dpython.home=<jython install directory> > as a JVM parameter. I think the purpose of using > jython-standalone-2.7.0.jar is to be able to run jython without > running installer. > > How do I specify jython-standalone-2.7.0.jar as python.home? I > think somehow it needs Lib directory which is inside of jar. > > > Any recommendations are appreciated. Thanks > > > > > > What's New with Xactly <http://www.xactlycorp.com/email-click/> > > <https://www.nyse.com/quote/XNYS:XTLY> LinkedIn > <https://www.linkedin.com/company/xactly-corporation> Twitter > <https://twitter.com/Xactly> Facebook > <https://www.facebook.com/XactlyCorp> YouTube > <http://www.youtube.com/xactlycorporation> > > > ------------------------------------------------------------------------------ > Monitor Your Dynamic Infrastructure at Any Scale With Datadog! > Get real-time metrics from all of your servers, apps and tools > in one place. > SourceForge users - Click here to start your Free Trial of Datadog now! > http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140 > > > _______________________________________________ > Jython-dev mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-dev |