Pycharm报错 : SyntaxError: Non-ASCII character 解决方法

最近重新装了一下pycharm出现了很多问题 素材///心塞塞,

如果让你重新来过
你还乱删注册表不

言归正传

如果python文件中有中文字符,且未声明编码,就会出现报错信息: File “encode.py”, line 1SyntaxError: Non-ASCII character ‘\xe7’ in file encode.py on line 1, but no encoding declared; see //…python…/dev/peps/pep-0263/ for details for details

根据错误提示,我们在python官网得到如下帮助信息:
1
Python will default to ASCII as standard encoding if no other encoding hints are given.

翻译:如果没有其他编码提示,Python将默认为ASCII作为标准编码。

To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file

翻译:要定义源代码编码,必须在源文件中第一行或第二行放置一个魔术注释(就像这样)
2

所以,按照帮助文档的提示以及例子,我们在Python文件中加入一个编码声明:

# coding=utf-8

在文档开头就好啦,问题解决√

猜你喜欢

转载自blog.csdn.net/qq_44702847/article/details/106242222