importing python modules from java

Jeffrey Hubbard hubbard.jeffrey at
Sat Feb 25 18:24:45 CET 2012

I have written a c++ library which embeds python functions as described in 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 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list