SyntaxError: Non-UTF-8 code starting with '\xb5' in file test.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

使用editplue运行如下程序,出现错误

hex_value1 = 0x13
print("hex_value1的值为:",hex_value1)

SyntaxError: Non-UTF-8 code starting with ‘\xb5‘ in file test.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

转载:

Eclipse+PyDev 出现 SyntaxError: Non-UTF-8 code starting with ‘\xb5‘ in file的代码编码问题

SyntaxError: Non-UTF-8 code starting with ‘\xb5‘ in file D:\eclipse-workspace\Pytest1\src\Ptest1\__init__.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

原因:

默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串。 当然你也可以

两种解决办法:

1、为源码文件指定不同的编码——直接在程序最前面加上如下语句,如gbk:

# coding=gbk

2、修改默认编码格式

在左侧Package Explorer里面找到相应的文件,点击右键选择“Properties”

把编码从默认:

改为:

保存之后再添入中文内容就可以正常运行了。
————————————————
版权声明:本文为CSDN博主「lenka_qin」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/oHuandream/article/details/83867736

SyntaxError: Non-UTF-8 code starting with '\xb5' in file test.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

原文地址:https://www.cnblogs.com/tangmixun/p/11600887.html

时间: 2024-10-12 09:46:43

SyntaxError: Non-UTF-8 code starting with '\xb5' in file test.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details的相关文章

python问题:SyntaxError:Non-ASCII character '\xe5' in file kNN.py on line 2, but no encoding declared;

因为Python在默认状态下不支持源文件中的编码所致.解决方案有如下三种: 一.在文件头部添加如下注释码: # coding=<encoding name> 例如,可添加# coding=utf-8 二.在文件头部添加如下两行注释码: #!/usr/bin/python # -*- coding: <encoding name> -*- 例如,可添加# -*- coding: utf-8 -*- 三.在文件头部添加如下两行注释码: #!/usr/bin/python # vim:

SyntaxError: Non-ASCII character &#39;\xe5&#39; in file a.py on line 9, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

SyntaxError: Non-ASCII character '\xe5' in file a.py on line 9, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details 在文件头部加: #-*-coding:utf-8-*- SyntaxError: Non-ASCII character '\xe5' in file a.py on line 9, but no enco

python - 中文打印报错SyntaxError: Non-ASCII character &#39;\xe4&#39; in file test.py on line 3, but no encoding declared。

python中默认的编码格式是ASCII格式, 所以在没修改编码格式时无法正确打印汉字. 解决办法: 在以后的每一个需要显示汉字的python文件中, 可以采用如下方法在 #!/usr/bin/python的下一行加上一句话来定义编码格式, 以utf-8编码为例: #!/usr/bin/python#coding:utf-8 特别注意:定义编码格式的这一行代码必须放在第一行或者第二行,一般如果第一行是提示python位置的代码, 那么定义编码格式的这一行就必须放在第二行,否则依然会提示错误. p

[已解决]关于python无法显示中文的问题:SyntaxError: Non-ASCII character &#39;\xe4&#39; in file test.py on line 3, but no encoding declared。

想在python代码中输出汉字.但是老是出现SyntaxError: Non-ASCII character '\xe4' in file test.py on line , but no encoding declared. (test.py是我自己的文件,提示错误出现在第4行, 你的文件也会得到相应的提示). 一个简单的示例test.py代码如下: 1 #!/usr/bin/python 2 3 print "你好吗" 在终端下执行python test.py指令之后, File

SyntaxError: Non-ASCII character &#39;\xe5&#39; in file test.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

python的默认编码文件是用的ASCII码,而你的python文件中使用了中文等非英语字符. 在Python源文件的最开始一行,加入一句: # coding=UTF-8 SyntaxError: Non-ASCII character '\xe5' in file test.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details 原文地址:https://w

SyntaxError: Non-ASCII character &#39;\xe7&#39; in file 9.py on line 13, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

解决方法: #!/usr/bin/python #-*-coding:utf-8-*- SyntaxError: Non-ASCII character '\xe7' in file 9.py on line 13, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

python出现SyntaxError: Non-ASCII character &#39;\xe6&#39; in file 打印日期.py on line 1, but no encoding declared;

刚开始学习python,照着书上敲的代码: #根据给定的年月日以数字的形式打印出来 months = [ 'January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ] #以1-31的数字作为结尾的列表 endings = ['st', 'nd', 'rd'] + 17 * ['th'] + ['st', 'nd',

python 运行时报错误SyntaxError: Non-ASCII character &#39;\xe5&#39; in file 1.py on line 2

File "1.py", line 2SyntaxError: Non-ASCII character '\xe5' in file 1.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details 原因是:Python默认是以ASCII作为编码方式的,需要在文件开头设置一下编码 # -*- coding: UTF-8 -*- 或者 #coding=utf

Non-UTF-8 code starting with &#39;\xff&#39;解决,记录

Python 代码编译时提示:SyntaxError: Non-UTF-8 code starting with '\xff' in file convert.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 查了网上各种解决办法,方法最多就是添加 1 # coding=gbk 或者 1 #-*- coding=utf-8 -*- 都没解决. 最后的解决方法是: