转载地址:http://www.tuicool.com/articles/FJnm2in
python2.7中的UnicodeDecodeError: 'ascii' codec can't decode byte 0 - 司空落星
使用ez_setup.py安装setuptools报错如下 Traceback (most recent call last): File "httpservice.py", line 5, in <module> import SimpleHTTPServer File "C:\Python27\lib\SimpleHTTPServer.py", line 27, in <module> class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): File "C:\Python27\lib\SimpleHTTPServer.py", line 208, in SimpleHTTPRequestHandler mimetypes.init() # try to read system mime.types File "C:\Python27\lib\mimetypes.py", line 358, in init db.read_windows_registry() File "C:\Python27\lib\mimetypes.py", line 258, in read_windows_registry for subkeyname in enum_types(hkcr): File "C:\Python27\lib\mimetypes.py", line 249, in enum_types ctype = ctype.encode(default_encoding) # omit in 3.x! UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)
解决方法:
通过分析最后的错误提示,是由于setuptools包中的setup.py编码格式错误,导致无法安装,以上虽然报错,但是setuptools-5.5.zip已经下载完成。那么就可以通过手工安装setuptools包:
2、修改setup.py,在代码中添加如下几句即可:
修改默认的编码方式
import sys
reload(sys)
sys.setdefaultencoding('gb18030')
3、在cmd窗口中进入Python27\Lib\site-packages\setuptools-5.5目录,然后输入:python setup.py install,即可安装成功
没有评论:
发表评论