ninia / jep

Embed Python in Java
Other
1.33k stars 150 forks source link

SyntaxError: no viable alternative at input ... #346

Closed mike-hunhoff closed 3 years ago

mike-hunhoff commented 3 years ago

When using Jep.runScript to execute a Python script containing

example = "!"
print(f"hello{example}\nworld")

I receive the error

SyntaxError: no viable alternative at input '"hello{example}\nworld"'

I'm unsure where the issue lies as the script file doesn't appear to be read before invoking cypthon PyRun_File at https://github.com/ninia/jep/blob/8a2746a2ff67d219d76733f05d526e4c65e9a177/src/main/c/Jep/pyembed.c#L1617

I'm interested to hear your thoughts on where the issue might be. tia

Jep: 4.0 Java: openjdk 11.0.12 Python: 3.9.6 OS: Ubuntu 20.04.2 LTS

bsteffensmeier commented 3 years ago

It works fine for me:

Code:

class Test {

    public static void main(String[] args) throws JepException {
        try (SharedInterpreter interpreter = new SharedInterpreter()) {
            interpreter.runScript("test.py");
        }
    }
}
example = "!"
print(f"hello{example}\nworld")

Output:

hello!
world
mike-hunhoff commented 3 years ago

Thank you for checking - I believe this was user error.