UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not i

关于在linux终端出现UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-2: ordinal not in range(128) 报错的解决方案

原因:

这是因为终端不支持中文显示导致的。

解决:

(1)设置环境变量LANG

修改~/.bash_profile文件,执行export LANG=“en_US.UTF-8” >> ~/.bash_profile
source ~/.bash_profile

(2)使用PYTHONIOENCODING

在运行python命令前添加参数 PYTHONIOENCODING=utf-8 python test.py
或者执行:export PYTHONIOENCODING=utf-8 >> ~/.bashrc
source ~/.bashrc

猜你喜欢

转载自blog.csdn.net/weixin_43922901/article/details/89244457
今日推荐