Python3默认字符编码的问题

输出报错

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

>>> import sys
>>> sys.stdout.encoding
'ANSI_X3.4-1968'

 

卸载Python

apt remove --purge python*

安装Python

apt install python3

apt install python3-pip

 

import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

 

posted @ 2023-02-17 18:57  华腾海神  阅读(21)  评论(0编辑  收藏  举报