不带interp的Java-Python

2024-04-23 14:39:55 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我在看各种Java包,它们允许您通过Java运行python代码。Jython不能处理相当于Python3.6的代码。所以基本上,我有用python3.6编写的代码,需要这样做。我需要能够通过Java使用python代码,而不需要python解释器。有这样的包裹吗?(注意,我不会更改python代码,因为这是一个框架,传统上在python中使用。 我有一个传统上通过python代码使用的python框架,当然是python3.6。相反,我想通过Java8代码来使用它。现在我查看了Jython,但它不能处理3.6或3.x。我不会改变框架中的python代码。此外,Java包应该能够在没有解释器的情况下运行python代码。有这样的事吗?Py4j需要python解释器。你知道吗


Tags: 代码框架情况传统jythonjava解释器java8
3条回答

不,运行Python代码需要一些Python解释器或其他解释器。你知道吗

GraalVM将Python代码编译为Java字节码,并使用graalpython在JVM上运行它,注意如下:

This Python implementation currently aims to be compatible with Python 3.7, but it is a long way from there, and it is very likely that any Python program that requires any imports at all will hit something unsupported. At this point, the Python implementation is made available for experimentation and curious end-users.

因为您不会更改它,所以可以将Python转换为可执行文件,并使用Java将其派生为新进程。你知道吗

ProcessBuilder pb = new ProcessBuilder("C:\\...\\file.exe", command arguments, ..., ...);
pb.start();

您可以使用文件I/O在Python和Java之间进行通信,这是最简单的解决方案。你知道吗

相关问题 更多 >