简体   繁体   中英

Java Python without interpreter

So I was looking at various packages for for Java that allow you to run python code via Java. Jython does not handle the equivalent of python 3.6 code. So basically, I have code written in python 3.6 and requires so. I need to be able to utilize that python code via Java without having a python interpreter. Is there such a package? (Note I will not be changing the python code because that is a framework and that traditionally be used in python. I have a python framework that would be traditionally utilized via python code of course, for python 3.6. Instead, I would like to be utilize it via Java 8 code. Now I looked into Jython but it does not handle 3.6 or 3.x for that matter. I will not be changing the python code from the framework. Additionally, the Java Package should be able to run the python code without an interpreter. Is there such a thing? Py4j requires a python interpreter.

GraalVM compiles Python code to Java bytecode and runs it on the JVM using graalpython , with this caveat:

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 代码需要一些 Python 解释器或其他。

Since you won't change it, you could convert the Python to an executable and use Java to spawn it as a new process.

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

You could use File I/O to communicate between Python and Java as the easiest solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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