From: Stefan R. <Ste...@gm...> - 2013-09-25 22:43:45
|
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div> <div>Hello everybody interested in the "import cv2" issue!</div> <div> </div> <div>I already answered the issue on a reply from the JyNI contact address, but maybe I should state it here on the Jython-userlist too - just in case someone else is also interested in the topic.</div> <div> </div> <div>>>I find it hard to assess the maturity</div> <div>Nobody claims maturity of JyNI - it is alpha state. Yes in the demo-file the import line needs to be modified because I had once trouble setting the Jython-Python path in my IDE, did a quick hack via System.path.append(blah) and later forgot to revert that. However, it is clearly mentioned in the intructions how to run the demo.</div> <div>(@Jeff: By the way, were you able to run the demo? What distribution did you use?)</div> <div> </div> <div>Now to the actual issue. Am I right, if I think that OpenCV is the targeted framework?</div> <div>If so, in my opinion JyNI would be the wrong way to use OpenCV via Jython, even if it were mature. This is because there are Java-bindings available for OpenCV (http://docs.opencv.org/2.4.4-beta/doc/tutorials/introduction/desktop_java/java_dev_intro.html), which should integrate seamlessly with Jython.</div> <div>To emulate the Python C-API, JyNI will always have a significant overhead. This is tolerable if one needs access to really Python-specific C-code like NumPy (which unfortunately does not work yet with JyNI). However if there are Java-bindings available, using the CPython bindings via JyNI would be a detour in any case (of course a simple Python-level abstraction layer should be written if one aims for code that is also runnable in CPython).</div> <div> <div> </div> <div>Secondly, doing "import cv2" seems for me like not even using the CPython bindings. In OpenCV's CPython tutorials, they usually write "import cv" (seemingly, also when it is scoped on OpenCV 2.x)</div> <div>Maybe cv2.so is part of the C++ library? Can that be? In that case importing it directly would only have a chance via ctypes, which would also be a detour compared to using the Java bindings. (I hope to be able to support ctypes in JyNI v2.7-alpha2, but don't count on it.)</div> <div> </div> <div>What really stuns me is that numpy is said to work. "import numpy" produces "ImportError: No module named numpy" and nothing else (with JyNI it currently produces undefined symbol errors or segmentation faults - please be patient on this issue). I doubt, this behaves different on other platforms. Only explanation would be that Numpy4J or something was used. (Or that accidently CPython was called instead of Jython).</div> <div> </div> <div>I hope this cleared the dust a bit.</div> <div> </div> <div>Cheers</div> <div> </div> <div>Stefan</div> <div> </div> <div> </div> <div style="margin: 10.0px 5.0px 5.0px 10.0px;padding: 10.0px 0 10.0px 10.0px;border-left: 2.0px solid rgb(195,217,229);"> <div style="margin: 0 0 10.0px 0;"><b>Gesendet:</b> Mittwoch, 25. September 2013 um 20:56 Uhr<br/> <b>Von:</b> "Jeff Allen" <ja...@fa...><br/> <b>An:</b> "Sneha Murganoor" <sne...@gm...><br/> <b>Cc:</b> jyt...@li...<br/> <b>Betreff:</b> Re: [Jython-users] Fwd: import .so files using PythonInterperter</div> <div> <div style="background-color: rgb(255,255,255);"> <div class="moz-cite-prefix">For option 1. I meant the usual JNI pattern of some C code of your own with a Java counterpart that you can then call from Jython. It's not a trivial task, but probably the only way realistically. I've been working lately on the JLine integration into Jython, which is an example of JNI.<br/> <br/> As for option 2, browsing the source of JyNI just now, I find it hard to assess the maturity. At least there's an example:<br/> <a class="moz-txt-link-freetext" href="https://github.com/Stewori/JyNI/blob/master/JyNI-Demo/src/JyNIDemo.py" target="_blank">https://github.com/Stewori/JyNI/blob/master/JyNI-Demo/src/JyNIDemo.py</a><br/> But you'll have to adapt the source unless your name is stefan!<br/> <br/> I meant to include the list in my first reply, so thanks for reflecting back (and to Alex for confirming the limitation).<br/> <br/> Jeff <pre class="moz-signature">Jeff Allen</pre> On 25/09/2013 11:40, Sneha Murganoor wrote:</div> <blockquote> <div> <div> <div> <div>Hi Jeff,<br/> </div> <div>Thanks Jeff..<br/> </div> I am still facing the problem after downloading JyNI and setting CLASSPATH to JyNI.jar.<br/> </div> I realize that only few modules as of now are supported by JyNI.<br/> </div> <div>I didn't understand your first option. Did you mean .. Java lib wrapping cv2.so and wrapping that Java lib into python library..</div> <div> </div> Thanks,<br/> Sneha <div class="gmail_extra"> <div class="gmail_quote">On Wed, Sep 25, 2013 at 1:04 PM, Jeff Allen <span><<a>ja...@fa...</a>></span> wrote: <blockquote class="gmail_quote" style="margin: 0 0 0 0.8ex;border-left: 1.0px rgb(204,204,204) solid;padding-left: 1.0ex;"> <div>Hello Sneha:<br/> <br/> You can't call loadable library code like that from Jython. (Conversely you can call JVM code in JAR files.) The library will conform to CPython calling conventions, so you won't be able to invoke it directly even from Java.<br/> <br/> I can think of two possibilities worth looking at, but I haven't used either myself:<br/> 1. Wrap the library with native code callable from Java and a class that loads that library. (Easy to say!)<br/> 2. <a href="http://www.jyni.org/" target="_blank">http://www.jyni.org/</a><br/> <br/> I'm surprised numpy works for you. Maybe it imports, but I'm pretty sure numpy doesn't *work* under Jython since it too has a native C part. <pre>Jeff Allen</pre> <div> <div> <div>On 25/09/2013 06:13, Sneha Murganoor wrote:</div> </div> </div> <blockquote> <div> <div> <div>Hi,<br/> <div> <div class="gmail_quote"> <div> <div> <div> <div> <div>I am facing probs to import .so file using PythonInterperter from Java.<br/> <br/> >From python:<br/> $ python<br/> Python 2.7.3 (default, Apr 10 2013, 06:20:15)<br/> [GCC 4.6.3] on linux2<br/> Type "help", "copyright", "credits" or "license" for more information.<br/> >>> import cv2<br/> >>> print cv2.__file__<br/> /usr/lib/pyshared/python2.7/cv2.so<br/> >>> exit<br/> Use exit() or Ctrl-D (i.e. EOF) to exit<br/> >>><br/> $<br/> <br/> </div> >From Java:<br/> PythonInterpreter ie = new PythonInterpreter();<br/> ie.exec("import cv2");<br/> <br/> $ javac InterperterExample.java<br/> $java InterperterExample<br/> Exception in thread "main" Traceback (most recent call last):<br/> File "<string>", line 1, in <module><br/> ImportError: No module named cv2<br/> <br/> </div> But importing other modules like numpy works perfectly fine.<br/> </div> <div>How to resolve this?<br/> </div> Thanks,</div> Sneha</div> </div> </div> </div> <fieldset> </fieldset> </div> </div> <pre>------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > <a href="http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk" target="_blank">http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk</a></pre> <fieldset> </fieldset> <pre>_______________________________________________ Jython-users mailing list <a>Jyt...@li...</a> <a href="https://lists.sourceforge.net/lists/listinfo/jython-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/jython-users</a> </pre> </blockquote> </div> </blockquote> </div> </div> </div> </blockquote> </div> </div> </div> </div> </div></div></body></html> |