码迷,mamicode.com
首页 > 编程语言 > 详细

启动运行python3时 UnicodeDecodeError: 'gbk' codec can't decode byte 0xa2 in position 170: illegal multibyte sequence

时间:2019-08-18 15:52:17      阅读:780      评论:0      收藏:0      [点我收藏+]

标签:参数   more   启动   打开   pac   erro   odi   edits   mat   

重现

在cmd中输入Python,运行后,出现以下错误:

Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site.py", line 439, in register_readline
    readline.read_history_file(history)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
    self.mode._history.read_history_file(filename)
  File "C:\ProgramData\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 0xa2 in position 170: illegal multibyte sequence

原因是在读取filename的时候,是以unicode来读取的,需要打开C:\ProgramData\Anaconda3\lib\site-packages\pyreadline\lineeditor\history.py这个文件。

技术图片

打开history.py,并编辑:

技术图片

假如encoding参数即可。

技术图片

启动运行python3时 UnicodeDecodeError: 'gbk' codec can't decode byte 0xa2 in position 170: illegal multibyte sequence

标签:参数   more   启动   打开   pac   erro   odi   edits   mat   

原文地址:https://www.cnblogs.com/heenhui2016/p/11372461.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!