[Solved] Docker Error: SyntaxError: Non-ASCII character ‘\xe5‘ in file xxx

Problem description

Use the following docker command to temporarily run the image: (XXX is a python file)

sudo docker run -it --rm -p 8888:8888 xxx

report errors:

SyntaxError: Non-ASCII character '\xe5' in file xxx on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Cause analysis

Unsupported character sets may be included when packaging docker images.

Solution

In the first line of dockerfile, add:

ENV LANG C.UTF-8

Read More: