importing python modules from java

Jeffrey Hubbard hubbard.jeffrey at ymail.com
Sat Feb 25 12:24:45 EST 2012


Hello,
I have written a c++ library which embeds python functions as described in http://docs.python.org/extending/embedding.html. Everything works fine, I can import and use modules such as numpy by calling PyImport_ImportModule(...).

Now I wrapped this c++ library for java using SWIG. However, when running inside this wrapper, an attempt to import numpy fails:
  PyObject *numpy_module = PyImport_ImportModule("numpy");
returns NULL for numpy_module.

I guess I have a similar problem as described in http://www.ibm.com/developerworks/aix/library/au-integratepython.html. It seems that since python 2.3 it is complicated to nest a module import in an embedded python environment. I don't understand the details of their explanations and I cannot use their solution to simulate the java executable, because the library is supposed to be part of an existing java framework.

Is there a possibility to import numpy from python2.6, embedded in a c++ library, which is dynamically loaded from java? I am working on Debian linux, if this matters.

Regards
Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120225/07c2d9ae/attachment.html>


More information about the Python-list mailing list