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