Python启动时遇到的UnicodeDecodeError解决方法

刚刚安装完的AtlasOS,刚装完Python启动时就遇到了这个奇怪的错误:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
C:\Users\Administrator>python
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
  File "D:\Python\lib\site.py", line 477, in register_readline
    readline.read_history_file(history)
  File "D:\Python\lib\site-packages\pyreadline3\rlmain.py", line 175, in read_history_file
    self.mode._history.read_history_file(filename)
  File "D:\Python\lib\site-packages\pyreadline3\lineeditor\history.py", line 90, in read_history_file
    for line in open(filename, 'r'):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb0 in position 57: illegal multibyte sequence

在分析了一波 D:\Python\Lib\site.py之后,得出了解决方法:

del /f /s /q %HOMEDRIVE%\Users\%username%\.python_history

原来是旧Windows的备份迁移过来之后会遇到编码不同的问题(?)

updatedupdated2023-07-202023-07-20
加载评论