在下面目录中新增文件: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‘
>>>
网友评论