1

I'm trying to run a polyglot native image with java/python. I'm able to create the native image with this command line:

 native-image --language:python javapython

But when a run it with ./javapython it throws me this error:

Startup failed, could not read core library from /lib-graalpython/builtins.py. Maybe you need to set python.CoreHome and python.StdLibHome.

Looking for this instruction I found this:

--python.CoreHome=<String>
--python.StdLibHome=<String>

I tried adding it with graalpython, with CoreHome it looks like it works, but with StdLibHome throws me another error:

Original exception was:

Traceback (most recent call last): File "/importlib/_bootstrap.py", line 986, in _find_and_load ModuleNotFoundError: No module named 'site'

Then run again ./javapython but it shows me the same error.

Does anyone know how to configure those paths or why this happened? Thanks

Steves
  • 2,798
  • 21
  • 21
Antonio
  • 115
  • 6

1 Answers1

3

GraalPython needs to know where to look for its core library files and also Python standard library files. Normally, the launcher ($GRAALVM_HOME/bin/graalpython) configures this, but if you embed GraalPython in your app, you need to provide it yourself.

One possibility is to export GRAAL_PYTHONHOME pointing to $GRAALVM_HOME/jre/languages/python (on JDK11 based GraalVM builds it would be $GRAALVM_HOME/languages/python). Another is to provide all the options when building the context:

Context context = Context.newBuilder()
              .option("python.CoreHome", "/path/to/graalvm/jre/languages/python/lib-graalpython")
              .option("python.StdLibHome", "/path/to/graalvm/jre/languages/python/lib-python/3")
              // ...
              .build()
Steves
  • 2,798
  • 21
  • 21
  • Thanks, it really works :). One last question, Is it the same process for Ruby with --home? Thanks – Antonio Jul 17 '20 at 01:41
  • no, I don't think so, the standardization and documentation for this is actually being worked on, so once that is out, I'll update the answer. – Steves Jul 18 '20 at 23:15
  • 1
    In case it is useful, regarding Ruby question, the approach looks a bit different and driven by JVM's system properties. You actually have to set two: `org.graalvm.language.ruby.home` and `llvm.home`. In case of Java 11 `-Dorg.graalvm.language.ruby.home=$GRAALVM_HOME/languages/ruby -Dllvm.home=$GRAALVM_HOME/languages/llvm`. And In case of Java 8, small adjustment, `-Dorg.graalvm.language.ruby.home=$GRAALVM_HOME/jre/languages/ruby -Dllvm.home=$GRAALVM_HOME/jre/languages/llvm` – reta Mar 07 '21 at 00:37