Run javax.script.ScriptEngine with Python 3

366 views Asked by At

I want to call classes/functions written in Python 3 from my Java library. For that, I tried to use javax.script.ScriptEngine;, but when I execute these lines:

ScriptEngine engine = new ScriptEngineManager().getEngineByName("python") ;
engine.eval("import sys") ;
engine.eval("print(sys.version)") ;

The python version loaded is 2.7 instead of the 3.6 version that I find (and need because the code I want to call is in Python 3.6) when executing the exact same lines into a terminal.

How can I load python 3.6 instead of 2.7?

0

There are 0 answers