关于Python3 打印中文乱码问题

解决方案有两种:

  1. 在命令行前指定编码
$ PYTHONIOENCODING=utf-8 python test.py
hello world
你好,世界
  1. 在代码中指定编码
import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
print('hello world')
print('你好,世界')

  3.终极解决方案是:指定系统的编码,将以下内容加入到系统配置文件中
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

猜你喜欢

转载自www.cnblogs.com/llfctt/p/11833383.html