命令行调用python出现编码错误:UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x9a in position 140 完美解决!
命令行输入python,出现一大串警告内容如下所示:
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "D:\anaconda3\lib\site.py", line 439, in register_readline
readline.read_history_file(history)
File "D:\anaconda3\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
self.mode._history.read_history_file(filename)
File "D:\anaconda3\lib\site-packages\pyreadline\lineeditor\history.py", line 82, in read_history_file
for line in open(filename, 'r'):
UnicodeDecodeError: 'gbk' codec can't decode byte 0x9a in position 140: illegal multibyte sequence
解决办法:
找到安装路径D:\anaconda3\Lib\site-packages\pyreadline\lineeditor中的history.py文件,第82行
for line in open(filename, 'r'):
改为
for line in open(filename, 'r', encoding='utf-8'):
完美解决!!
本文地址:https://blog.csdn.net/j18233653274/article/details/107448595