power shell下进入python后系统提示gbk错误,改编码

背景

  • power shell (CMD) 界面下,输入python进入python环境时,系统提示gbk错误, 但能进入、使用
  • 提示错误来自于history file相关
    power shell下进入python后系统提示gbk错误,改编码
  • win10, anaconda 4.8.3, python 3.8.3
  • 可能其它小程序更改了系统的编码

办法

  • 根据上述提示,找到history.py文件, 备份一份
  • 找到错误行数,增加 encoding=‘utf-8’
  • 原来: for line in open(filename, ‘r’):
    更改后: for line in open(filename, ‘r’, encoding=‘utf-8’):