美文网首页PythonLinuxPython 运维
【神奇的 Linux】设置系统 Python 默认编码 UTF-

【神奇的 Linux】设置系统 Python 默认编码 UTF-

作者: 清醒的cola | 来源:发表于2016-12-20 13:09 被阅读54次

困扰多年的编码问题

UnicodeDecodeError: 'ascii' codec can't decode byte 0xa1 in position 36: ordinal not in range(128)

设置下系统 Python 默认编码

  1. 需要在site-packages 下 touch sitecustomize.py
  2. vim 一下
import sys  
sys.setdefaultencoding('utf-8')   
  1. 验证一下 python -c "import sys; print(sys.getdefaultencoding())"

相关文章

网友评论

    本文标题:【神奇的 Linux】设置系统 Python 默认编码 UTF-

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