在使用之前的代码时,报错:
File “F:\File_Anaconda‚0CV\yolov5-master‚00701.py”, line 5
SyntaxError: Non-UTF-8 code starting with ‘À’ in file F:\File_Anaconda‚0CV\yolov5-master‚00701.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
File "F:\File_Anaconda‚0CV\yolov5-master‚00701.py", line 5
SyntaxError: Non-UTF-8 code starting with 'À' in file F:\File_Anaconda‚0CV\yolov5-master‚00701.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
同样问题的截图
主要报错信息内容翻译如下所示:
File "F:\File_Anaconda‚0CV\yolov5-master‚00701.py", line 5
SyntaxError: Non-UTF-8 code starting with 'À' in file F:\File_Anaconda‚0CV\yolov5-master‚00701.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
翻译:
文件”F: \ File_Anaconda \ 2020CV\ yolov5-master \ 20200701。py”,第5行
文件F:\File_Anaconda‚0CV\yolov5-master‚00701.py中以'À'开头的非utf-8代码,在第5行没有声明编码;详情请参阅http://python.org/dev/peps/pep-0263/
经过查阅资料,发现是编码格式不统一,导致乱码了。
小伙伴们按下面的解决方法即可解决!!!
要解决这个错误,需要将此代码放在程序最上端,此处#
而不是注释,是因为其是告诉系统的utf-8支持中英文。
将此代码放在程序最上端:
# -*- coding: utf-8 -*-
或
# coding=utf-8
将此代码放在程序最上端:
# -*- coding: gbk -*-
或
# coding=gbk