解决Python报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 658: ill

编程入门 行业动态 更新时间:2024-10-28 17:14:56

解决Python报错–UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 658: illegal multibyte sequence

今天在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'


再次运行Python就不会报错了。

更多推荐

解决Python报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80

本文发布于:2023-06-14 01:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1421432.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   codec   decode   gbk   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!