python3启动编码错误

0
用cmd启动python提示编码错误
C:\Users\chin>python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45) [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 "E:\anaconda\lib\site.py", line 410, in register_readline
    readline.read_history_file(history)
  File "E:\anaconda\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
    self.mode._history.read_history_file(filename)
  File "E:\anaconda\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 0x89 in position 1079: illegal multibyte sequence
>>>
在v2ex上看到类似的问题,但是重装python解决的。但不想这样做,同样的问题还会无法解决。
多个文件出现问题,是site.py rlmain.py还是history.py呢,抑或是全部有问题呢
已邀请:
0

ID王大伟 - 人生苦短,我选Python。 2017-11-21 回答

你使用了gbk去解码
如果你的内容不是gbk编码就会报错
你试试utf-8解码
0

ireno 2018-10-15 回答

from __future__ import print_function, unicode_literals, absolute_import
import re, operator, string, sys, os
from pyreadline.unicode_helper import ensure_unicode, ensure_str
os.path.expanduser(ensure_str('~/.history'))
 
把这个目录下的python history文件删除掉就好了
 
0

xiaotaomi - 努力脱贫的女汉子 2019-10-16 回答

buzhidao

要回复问题请先登录注册