使用pip安装框架的时候,总是提示说有编码错误,百度一番。原来是因为windows用的是gbk编码,发现需要在
C:\ProgramData\Anaconda3\Lib\site-packages\pip\basecommand.py
加入以下代码:
import importlib,sys
importlib.reload(sys)
sys.setdefaultencoding('gbk')
但是安装框架时候,提示:AttributeError: module 'sys' has no attribute 'setdefaultencoding'
Python
3
和2
的一个最大区别就在于字符串编码格式:引用:The encoding of py3.x is
hard-wired to "utf-8"
and changing it raises an error.所以如果你想改的话,只能在字符串输出时加上
.encode("GBK")