今天在anaconda上新建一个python3.6环境后,使用时报错了:
(base) C:\Users\peter>activate tf
(tf) C:\Users\peter>python
Python 3.6.7 (default, Feb 28 2019, 07:28:18) [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:\Users\peter\AppData\Local\Continuum\anaconda3\envs\tf\lib\site.py", line 410, in register_readline
readline.read_history_file(history)
File "C:\Users\peter\AppData\Local\Continuum\anaconda3\envs\tf\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
self.mode._history.read_history_file(filename)
File "C:\Users\peter\AppData\Local\Continuum\anaconda3\envs\tf\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 658: illegal multibyte sequence
网上查阅资料后发现这是win10下特有的问题
解决方案如下:
打开报错的倒数第三行的history.py文件,定位到82行,源代码如下:
添加代码
,encoding='utf-8'