原文链接:http://www.juzicode.com/archives/2189
错误提示:
运行py文件,提示 SyntaxError错误: File “hello.py”, line 3
SyntaxError: Non-UTF-8 code starting with ‘\xbd’ in file hello.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

大意是 py文件的第3行有个字符不是utf8编码。
对应的hello.py文件内容:

错误原因:
1、默如果在python文件的第一行没有声明py文件的编码方式, python3 默认是采用utf8编码,当py文件实际上是别的编码方式时,就会导致该错误。
解决方法:
1、修改py文件的编码方式为utf8方式。用notepad的格式转换功能,转换为utf8无bom编码格式:

2、如果实际是以ANSI格式编码(可以通过上图格式选项,看黑点所在的行是哪一个确认其编码方式),在文件第1行声明采用GBK编码或者cp936编码:

关注微信公众号:“桔子code”,欢迎后台留言撩我,我会尽我所能为你解惑Python,C等编程知识
