Search code examples
javapythonnumpyjython

Run python script (with numpy dependency) from java


In a java application I need to use a specific image processing algorithm that is currently implemented in python. What would be the best approach, knowing that this script uses the Numpy library ?

I alreayd tried to compile the script to java using the jythonc compiler but it seems that it doesn't support dependencies on native libraries like Numpy. I also tried to use Jepp but I get an ImportError when importing Numpy, too.

Any suggestion ?


Solution

  • If you're using Numpy you probably have to just use C Python, as it's a compiled extension. I'd recommend saving the image to disk, perhaps as a temporary file, and then calling the Python as a subprocess. If you're dealing with binary data you could even try memory mapping the data in Java and passing in in the path to the subprocess.

    Alternatively, depending on your circumstances, you could set up a simple data processing server in Python which accepts requests and returns processed data.