1

There is a way to run Python scripts that uses packages from Java using GraalVM and its Python module graalpython. Here is example https://github.com/paulvi/graalpython-java-template

I wonder if it is possible to bundle GraalVM engine and graalpython into my Java application and produce jar or native image (e.g. using native image compiler from GraalVM project ) ?

Paul Verest
  • 60,022
  • 51
  • 208
  • 332

1 Answers1

1

I think you can bundle whole GraalVM distribution with your application, like some other applications do with normal JDKs (e.g., I think IntelliJ bundles JDK with it). That would be the simplest option.

You need at least the GraalPython home directory, which contains Python standard library and other files necessary for GraalPython to run any meaningful program.

Moreover, if you want to run in JVM mode, then you need to run on GraalVM, other JDKs are not supported. In theory you could perhaps hack it somehow to run GraalPython on stock JDK with JVMCI, like it is possible with JavaScript [0], but it is going to be much more complicated with GraalPython.

In theory, you can bundle GraalPython home directory into your application by providing custom filesystem implementation [1].

[0] https://www.graalvm.org/reference-manual/js/RunOnJDK/

[1] https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html

Steves
  • 2,798
  • 21
  • 21