修复ubuntu下中文编码问题 tag: 命令行/乱码/编码 这个问题很难弄。还会影响到python的系统函数os.stat等。 解决方法如下: 执行命令: ```bash apt-get install -y locales locale-gen en_US.UTF-8 ``` 修改配置文件: ```bash vim ~/.bashrc ## 写入 export PYTHONIOENCODING=utf-8 export LANG='en_US.UTF-8' export LC_ALL='en_US.UTF-8' ``` 有时,它会报错: ``` warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8) ``` 此时需要: ``` echo "LC_ALL=en_US.UTF-8" >> /etc/environment echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen echo "LANG=en_US.UTF-8" > /etc/locale.conf locale-gen en_US.UTF-8 ``` 来自 大脸猪 写于 2017-01-03 01:43 -- 更新于2025-03-05 13:35 -- 0 条评论