当前位置:   article > 正文

Python异常002:SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xbc in position 0: invalid

syntaxerror: (unicode error) 'utf-8' codec can't decode byte 0xbc in positio

报错日志:

SyntaxError                               Traceback (most recent call last)
F:\XXX\lib\site-packages\IPython\core\interactiveshell.py in safe_execfile(self, fname, exit_ignore, raise_exceptions, shell_futures, *where)
   2721                     fname, glob, loc,
-> 2722                     self.compile if shell_futures else None)
   2723             except SystemExit as status:

F:\XXX\lib\site-packages\IPython\utils\py3compat.py in execfile(fname, glob, loc, compiler)
    167         compiler = compiler or compile
--> 168         exec(compiler(f.read(), fname, 'exec'), glob, loc)
    169 

SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xbc in position 0: invalid start byte (metrics.py, line 2)

During handling of the above exception, another exception occurred:

UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-17-68f53d19bb83> in <module>
----> 1 get_ipython().run_line_magic('run', '../playML/metrics.py')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

原因:
我这个电脑不能安装IDE环境,所以我自己用记事本写的Python文件,直接将后缀改为py。此时出现了一个问题,保存文件默认是ANSI编码,Python无法解析,需要将其换成Unicode编码。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/433190
推荐阅读
相关标签
  

闽ICP备14008679号