> I am using org.python.util.PythonInterpreter to embed Jython in a Java application. I am using Jython version 2.5.2.
> The python script I am interpreting contains UTF-8 literals and so I've added the Python Source Code Encoding at the top of the script as per PEP-0263:

The problem here is that you should as passing a unicode string to the compile function.

According to PEP-263, this is not permitted. See this issue for a detailed discssion.

PythonInterpreter.exec(String) should reject magic encoding comments like compile(unicode)

The solution in this case is to decode the file from UTF-8 at file read time, using something like an InputStreamReader


> String script = codecs.open() // load from file as a single String ...
> PythonInterpreter pi = new PythonInterpreter();
> PyCode code = pi.compile(script);
> result = pi.eval(code);