V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
hao1032
V2EX  ›  问与答

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

  •  
  •   hao1032 · 2018-02-05 10:53:06 +08:00 · 2459 次点击
    这是一个创建于 2243 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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)
    8 条回复    2018-02-05 18:51:20 +08:00
    aver4vex
        1
    aver4vex  
       2018-02-05 11:25:01 +08:00
    print(u"您好,地球")
    topbandit
        2
    topbandit  
       2018-02-05 11:28:15 +08:00
    locale 命令 看看系统编码
    h4lbhg1G
        3
    h4lbhg1G  
       2018-02-05 11:28:40 +08:00
    export LC_ALL=en_US.UTF-8
    guinner
        4
    guinner  
       2018-02-05 11:30:01 +08:00 via iPhone
    把这个参数设对了应该就好了
    LC_CTYPE="en_US.UTF-8"
    nasmatic
        5
    nasmatic  
       2018-02-05 11:30:51 +08:00
    print(u'主题')
    hao1032
        6
    hao1032  
    OP
       2018-02-05 11:50:54 +08:00
    vim /etc/locale.conf
    LANG='zh_CN.UTF-8'

    解决,多谢大家的建议。
    guog
        7
    guog  
       2018-02-05 13:17:06 +08:00 via Android
    楼上的大神们,Python3 哪来的 u🌚
    Eds1995
        8
    Eds1995  
       2018-02-05 18:51:20 +08:00 via Android
    @guog 他们还活在 Python2
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3106 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 14:33 · PVG 22:33 · LAX 07:33 · JFK 10:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.