Search code examples
intellij-ideagraalvmpolyglot

GraalVM: How do I import libraries from different languages in a single project? I am using IntelliJ


I have to make some functions that will use different lanaguages (python, R, js).

I got stuck at the part of generating random numbers in Python to initialize a list with random elements. I looked up on ways of initializing random lists, and then I decided to use result = polyglot.eval("python", "[random.randint(0,10) for i in range(20)];").

The problem that I face now is that I need to import the "random" library from python, or whatever libraries will I need from different languages. I heard that it might be a problem with the dependencies, but I am not sure...

What am I supposed to do? Is it even possible to import libraries from more languages in a single project? What other alternatives do I have?


Solution

  • Note that solution for different dynamic languages may differ.

    Also js component is stable, while python (as of 2021) is still experimental.

    Here is example for Python with modules https://github.com/paulvi/java-python-graalvm-template

    And if you really do polyglot (using Python object in Java code), see https://github.com/hpi-swa-lab/graalpython-java-example

    There is still issue how to actually deploy this in production https://github.com/hpi-swa-lab/graalpython-java-example/issues/6 as just bundling venv subfolder into jar, will just work. One solution is in ttps://github.com/paulvi/java-python-graalvm-template

    Also randon, i.e. any library with graalvm is still big issue, as different packages have different issues, see https://github.com/oracle/graalpython/issues/228

    I suggest, that before really mixing a lot of languages, just try one, e.g. js that is more stable, make it work, and then try next.

    BTW PyCharm does not yet support graalpython.

    If you do any open source, or later find somethin new, please let me know via GitHub issue