报错信息
在Windows命令行环境下启动Python3.6,报如下错误
C:\Users\gaozh>python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "C:\Anaconda3\lib\site.py", line 418, in register_readline
readline.read_history_file(history)
File "C:\Anaconda3\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
self.mode._history.read_history_file(filename)
File "C:\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 0x80 in position 407: illegal multibyte sequence
解决办法
解决这个问题的方法就是修改文件 C:\Anaconda3\lib\site-packages\pyreadline\lineeditor\history.py
中对应的第82行的代码,添加编码格式为 utf-8
,然后重新启动Python即可。
参考文章
- https://github.com/pyreadline/pyreadline/issues/38