SyntaxError: invalid or missing encoding declaration怎么解决

SyntaxError: invalid or missing encoding declaration
(语法错误: 无效或缺失编码声明)

报错

在这里插入图片描述
再测试一下,输出中文都不行了,
在这里插入图片描述
在这里插入图片描述
乱码
在这里插入图片描述
shell里面是好的,所以确定是pycharm的问题。

解决

在这里插入图片描述
左上角文件>>设置>>编辑器>>文件编码:
在这里插入图片描述
解决成功:
在这里插入图片描述

Exception in thread Thread-7: Traceback (most recent call last): File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\tokenize.py", line 330, in find_cookie line_string = line.decode('utf-8') UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 25: invalid continuation byte During handling of the above exception, another exception occurred: Traceback (most recent call last): File "_pydevd_bundle/pydevd_cython.pyx", line 532, in _pydevd_bundle.pydevd_cython.PyDBFrame._handle_exception File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 16, in getline lines = getlines(filename, module_globals) File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 47, in getlines return updatecache(filename, module_globals) File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 136, in updatecache with tokenize.open(fullname) as fp: File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\tokenize.py", line 394, in open encoding, lines = detect_encoding(buffer.readline) File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\tokenize.py", line 371, in detect_encoding encoding = find_cookie(first) File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\tokenize.py", line 335, in find_cookie raise SyntaxError(msg) SyntaxError: invalid or missing encoding declaration for 'D:\\project\\desktop_jijun\\desktop_jijun\\desktop_jijun.py' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\tokenize.py", line 330, in find_cookie line_string = line.decode('utf-8') UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 25: invalid continuation byte During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner self.run() File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "D:\project\desktop_jijun\desktop_jijun\desktop_jijun.py", line 179, in consaltant with sr.Microphone() as source: File "_pydevd_bundle/pydevd_cython.pyx", line 1366, in _pydevd_bundle.pydevd_cython.SafeCallWrapper.__call__ File "_pydevd_bundle/pydevd_cython.pyx", line 322, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_exception File "_pydevd_bundle/pydevd_cython.pyx", line 452, in _pydevd_bundle.pydevd_cython.PyDBFrame.handle_user_exception File "_pydevd_bundle/pydevd_cython.pyx", line 535, in _pydevd_bundle.pydevd_cython.PyDBFrame._handle_exception File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 16, in getline lines = getlines(filename, module_globals) File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 47, in getlines return updatecache(filename, module_globals) File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 136, in updatecache with tokenize.open(fullname) as fp: File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\tokenize.py", line 394, in open encoding, lines = detect_encoding(buffer.readline) File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\tokenize.py", line 371, in detect_encoding encoding = find_cookie(first) File "C:\Users\lry20\AppData\Local\Programs\Python\Python38\lib\tokenize.py", line 335, in find_cookie raise SyntaxError(msg) SyntaxError: invalid or missing encoding declaration for 'D:\\project\\desktop_jijun\\desktop_jijun\\desktop_jijun.py' 语音输入后爆出这个错误,原因是什么
最新发布
06-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值