关于在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