美文网首页Python
linux : 各个发行版中修改python27默认编码为utf

linux : 各个发行版中修改python27默认编码为utf

作者: 凤箫之舞 | 来源:发表于2020-10-19 16:48 被阅读0次

    在下面目录中新增文件:sitecustomize.py

    内容为

    #coding=utf-8
    import sys
    
    reload(sys)
    sys.setdefaultencoding(‘utf8‘)
    

    各个发行版放置位置:

    RedHat:

    /usr/local/python27/lib/python2.7/site-packages/

    Ubuntu

    /usr/lib/python2.7

    其他发行版

    /usr/local/lib/python.27/site-packages

    测试一下:使用sys.getdefaultencoding()测试,看返回是不是utf8

    [root@base7565 site-packages]# python
    Python 2.7.14 (default, Sep  2 2019, 14:26:39)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.getdefaultencoding()
    ‘utf8‘
    >>>
    

    相关文章

      网友评论

        本文标题:linux : 各个发行版中修改python27默认编码为utf

        本文链接:https://www.haomeiwen.com/subject/ipxlmktx.html