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

problem

File "a1.py", line 1

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

Run python a1.py in ubuntun, the above error appears, follow the prompt to view the given connection  http://python.org/dev/peps/pep-0263/ 

 

Webpage snapshot ↓ (Webpage translation_Chinese)

 

Web snapshot (English)

 

solution

Add in the first line of the .py source file

 

# coding=<encoding name>

或者

#!/usr/bin/python
# -*- coding: <encoding name> -*-

或者

#!/usr/bin/python
# vim: set fileencoding = <encoding name>: 

Mainly meet the following regular expressions
^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)

Examples

Add the following comment to the first line of the file:

 

# encoding=utf-8

or

# encoding:utf-8

or

# coding=utf-8

or

# coding:utf-8


 

Guess you like

Origin www.cnblogs.com/LinQingYang/p/12710997.html