UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xcb in position 260: ordinal not in range(128)
1、Python setup.py文件安装是报错
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcb in position 260: ordinal not in range(128)
XXX在网上找到如下解决办法,但是不能解决问题
对于python3.x ,添加以下语句
import importlib,sys
importlib.reload(sys)
对于python2.7,添加以下语句
mport sys
reload(sys)
sys.setdefaultencoding('utf8')
实际解决
先测试现有python的默认编码,发现是'ANSI_X3.4-1968',即一种ASCII编码
因此需要设置python3.6编码方式为utf8,即
在~/.bash_profile中添加环境变量
export PYTHONIOENCODING=utf-8
然后source ~/.bash_profile激活
但是依然报错,出错的语句为
with open('README.md') as fid:
content = fid.read()
改成以下形式
with open('README.md', encoding='utf-8') as fid:
content = fid.read()
成功!
本文地址:https://blog.csdn.net/muyeluo123/article/details/107164155
上一篇: 动态规划详解(leetcode例题+解析)python
下一篇: Java语言:使用*号输出一个梯形
推荐阅读
-
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xcb in position 260: ordinal not in range(128)
-
Python2.7更新pip:UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 7: ordinal not in range(128)
-
【python】pip安装报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 7: ordinal not i
-
[解决]SyntaxError: ‘ascii‘ codec can‘t decode byte 0xe6 in position 4: ordinal not in range (128)
-
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8b in position 6: ordinal not in range(128)
-
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xcb in position 260: ordinal not in range(128)
-
python3 报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position...[报错篇]
-
Python2.7更新pip:UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 7: ordinal not in range(128)
-
pickle报UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xff in position 0:
-
[解决]SyntaxError: ‘ascii‘ codec can‘t decode byte 0xe6 in position 4: ordinal not in range (128)