简体   繁体   English

GraalVM:如何在单个项目中导入不同语言的库? 我正在使用 IntelliJ

[英]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).我必须制作一些使用不同语言(python、R、js)的函数。

I got stuck at the part of generating random numbers in Python to initialize a list with random elements.我陷入了在 Python 中生成随机数以使用随机元素初始化列表的部分。 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)];") .我查找了初始化随机列表的方法,然后我决定使用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.我现在面临的问题是我需要从 python 导入“随机”库,或者我需要从不同语言导入的任何库。 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?我还有什么其他选择?

Note that solution for different dynamic languages may differ.请注意,不同动态语言的解决方案可能会有所不同。

Also js component is stable, while python (as of 2021) is still experimental. js 组件也很稳定,而 python(截至 2021 年)仍处于试验阶段。

Here is example for Python with modules https://github.com/paulvi/java-python-graalvm-template这是带有模块的 Python 示例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如果你真的做多语言(在 Java 代码中使用 Python 对象),请参阅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.如何在生产https://github.com/hpi-swa-lab/graalpython-java-example/issues/6 中实际部署它仍然存在问题,因为只是将 venv 子文件夹捆绑到 jar 中,就可以工作了。 One solution is in ttps://github.com/paulvi/java-python-graalvm-template一种解决方案是在 ttps://github.com/paulvi/java-python-graalvm-template

Also randon, ie any library with graalvm is still big issue, as different packages have different issues, see https://github.com/oracle/graalpython/issues/228还有 randon,即任何带有 graalvm 的库仍然是个大问题,因为不同的包有不同的问题,请参阅https://github.com/oracle/graalpython/issues/228

I suggest, that before really mixing a lot of languages, just try one, eg js that is more stable, make it work, and then try next.我建议,在真正混合多种语言之前,先尝试一种,例如更稳定的 js,使其工作,然后再尝试下一个。

BTW PyCharm does not yet support graalpython .顺便说一句,PyCharm 尚不支持graalpython

If you do any open source, or later find somethin new, please let me know via GitHub issue如果你做了任何开源,或者以后发现了一些新的东西,请通过GitHub issue告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM