解决terminal运行python时,UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 234: illegal multibyte sequence报错问题
问题描述
今天偶然在pycharm的terminal运行python时发现有如下警告问题。
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 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:\Users\15619\anaconda3\envs\testenv\lib\site.py", line 440, in register_readline
readline.read_history_file(history)
File "C:\Users\15619\anaconda3\envs\testenv\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
self.mode._history.read_history_file(filename)
File "C:\Users\15619\anaconda3\envs\testenv\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 234: illegal multibyte sequence
解决方法
打开Anaconda的安装路径,如C:\Users\15619\anaconda3\Lib\site-packages\pyreadline\lineeditor中的history.py文件,找到第82行位置的如下代码:for line in open(filename, 'r'): 替换为如下:
for line in open(filename, 'r', encoding='utf-8'):
|