zoukankan      html  css  js  c++  java
  • [Bug]Python3.x SyntaxError: 'ascii' codec can't decode byte 0xe4 in position

    安装arch后就没再用python了
    昨天管服务器的大佬在跑贝叶斯分类器的时候发现正确率有问题
    我赶紧去做优化,然后就有这样的报错

    Python 3.6.4 (default, Jan  5 2018, 02:35:40) 
    [GCC 7.2.1 20171224] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print("中文")
      File "<stdin>", line 0
        ^
    SyntaxError: 'ascii' codec can't decode byte 0xe4 in position 7: ordinal not in range(128)
    >>> 
    

    我很费解啊,用了各种encode,decode没用啊
    最后发现$LANG不正常

    tanglizi@archlinux:~$ echo $LANG
    C
    

    尴尬,安装arch的时候光注意做引导了,忘了locale-gen
    于是修改LANG试了试,没什么问题

    tanglizi@archlinux:~$ LANG=en_US.UTF-8 python
    Python 3.6.4 (default, Jan  5 2018, 02:35:40) 
    [GCC 7.2.1 20171224] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print("中文")
    中文
    >>> 
    

    结果就是LANG不正确,对arch用户如下配置即可

    vim /etc/locale.gen
    locale-gen
    echo LANG=en_US.UTF-8 > /etc/locale.conf
    
  • 相关阅读:
    制作ubuntu容器完整步骤
    linux系统python3安装pip
    ssh连接服务器提示拒绝了密码
    ubuntu中vi编辑中按键错误
    虚拟机ubuntu连不上网
    NOIP2020退役记
    【NOIp2020游记】
    loki简单安装配置使用
    .net下com调用支持x86/x64
    nginx 504 Gateway Time-out
  • 原文地址:https://www.cnblogs.com/tanglizi/p/8455171.html
Copyright © 2011-2022 走看看