在 centos 下 python3,不能 print 中文,应该是什么原因啊,求教

2018-02-05 10:53:06 +08:00
 hao1032
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('tango')
tango
>>> 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 6.2 (Final)
2481 次点击
所在节点    问与答
8 条回复
aver4vex
2018-02-05 11:25:01 +08:00
print(u"您好,地球")
topbandit
2018-02-05 11:28:15 +08:00
locale 命令 看看系统编码
h4lbhg1G
2018-02-05 11:28:40 +08:00
export LC_ALL=en_US.UTF-8
guinner
2018-02-05 11:30:01 +08:00
把这个参数设对了应该就好了
LC_CTYPE="en_US.UTF-8"
nasmatic
2018-02-05 11:30:51 +08:00
print(u'主题')
hao1032
2018-02-05 11:50:54 +08:00
vim /etc/locale.conf
LANG='zh_CN.UTF-8'

解决,多谢大家的建议。
guog
2018-02-05 13:17:06 +08:00
楼上的大神们,Python3 哪来的 u🌚
Eds1995
2018-02-05 18:51:20 +08:00
@guog 他们还活在 Python2

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/428507

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX