Hello. I am using Jep to execute python scripts from within a Java application. Even with the numpy work around using shared modules I still get funny behavior. See the test case below.
import jep.Jep; import jep.JepConfig; public class JepTest { private static String script = "import numpy as np\n" + "from skimage.io import imread\n" + "testImagePath = '<path to test image>'\n" + "testImage = imread(testImagePath)\n"; private static JepConfig jepConfig = null; private static final String[] sharedModules = {"numpy", "scipy", "skimage", "skimage.transform", "skimage.io"}; public static void main(String[] args) { try { jepConfig = new JepConfig(); jepConfig.addSharedModules(sharedModules); Jep jep = new Jep(jepConfig); //jep.set("_pythonScript", script); //jep.eval("exec _pythonScript"); //jep.eval("del _pythonScript"); jep.eval("exec \"\"\"" + script + "\"\"\""); System.out.println("Finished with script..."); jep.close(); } catch (Exception e) { System.out.println("Caught Jep Exception:"); e.printStackTrace(); } } }
This results in the following error:
Caught Jep Exception:
jep.JepException: <type 'exceptions.IOError'>: file() constructor not accessible in restricted mode
at /usr/lib/python2.7/dist-packages/PIL/Image.open(Image.py:1996)
at /usr/lib/python2.7/dist-packages/skimage/io/_plugins/pil_plugin.imread(pil_plugin.py:21)
at /usr/lib/python2.7/dist-packages/skimage/io/_plugins/plugin.call(plugin.py:105)
at /usr/lib/python2.7/dist-packages/skimage/io/_io.imread(_io.py:150)
Evidently the jep sub-interpreter is running in restricted execution
mode. I get the same behavior by saving the script as a file and using Jep.runScript(). Is there a way to fix this? Any suggestions are appreciated.
Thanks,
Erik
--
You received this message because you are subscribed to the Google Groups "Jep Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jep-project+unsubscribe@googlegroups.com.
To post to this group, send email to jep-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jep-project/579d996e-12ae-413b-8342-6f391cee76a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/jep-project/CANOQTQGZ_91NccN3AAeKHdd%2BQecO%2Bc7LQjWsCDUYWE86%2BLw1sg%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to jep-project...@googlegroups.com.
To post to this group, send email to jep-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jep-project/579d996e-12ae-413b-8342-6f391cee76a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Jep Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jep-project...@googlegroups.com.