hao1032
V2EX  ›  问与答

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

  •  
  •   hao1032 · Feb 5, 2018 · 3392 views
    This topic created in 3055 days ago, the information mentioned may be changed or developed.
    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 replies    2018-02-05 18:51:20 +08:00
    aver4vex
        1
    aver4vex  
       Feb 5, 2018
    print(u"您好,地球")
    topbandit
        2
    topbandit  
       Feb 5, 2018
    locale 命令 看看系统编码
    h4lbhg1G
        3
    h4lbhg1G  
       Feb 5, 2018
    export LC_ALL=en_US.UTF-8
    guinner
        4
    guinner  
       Feb 5, 2018 via iPhone
    把这个参数设对了应该就好了
    LC_CTYPE="en_US.UTF-8"
    nasmatic
        5
    nasmatic  
       Feb 5, 2018
    print(u'主题')
    hao1032
        6
    hao1032  
    OP
       Feb 5, 2018
    vim /etc/locale.conf
    LANG='zh_CN.UTF-8'

    解决,多谢大家的建议。
    guog
        7
    guog  
       Feb 5, 2018 via Android
    楼上的大神们,Python3 哪来的 u🌚
    Eds1995
        8
    Eds1995  
       Feb 5, 2018 via Android
    @guog 他们还活在 Python2
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2641 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 14:47 · PVG 22:47 · LAX 07:47 · JFK 10:47
    ♥ Do have faith in what you're doing.