解决 ‘ascii’ codec can’t decode byte 0xe4 in position 7: ordinal not in range(128)
实验:
Python 3.5.4 (default, Jan 10 2018, 14:59:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('123asd')
123asd
>>> print('主题')
File "<stdin>", line 0
^
SyntaxError: 'ascii' codec can't decode byte 0xe4 in position 7: ordinal not in range(128)
系统版本:
>cat /etc/redhat-release
CentOS Linux release 7.2 (Final)
分析:
这是系统编码的问题
locale 命令 看看系统编码
[a@ ~/a]$ locale
LANG=C
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=en_US
执行:
export LC_ALL=en_US.UTF-8
或者
vim /etc/locale.conf
LANG='en_US.UTF-8'
原创文章,转载请注明: 转载自URl-team