python2.7
window环境
安装解析器lmxl时报错,报错内容如下:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 7: ordinal not in range(128)
C:\Python27\Lib\site-packages>easy_install lxml
Searching for lxml
Reading https://pypi.python.org/simple/lxml/
Best match: lxml 3.5.0
Downloading https://pypi.python.org/packages/2.7/l/lxml/lxml-3.5.0.win-amd64-py2
.7.exe#md5=9d0c481f78928cd9d5a6b7f9fc53edef
Processing lxml-3.5.0.win-amd64-py2.7.exe
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\easy_install.py", line 5, in <module>
main()
File "C:\Python27\Lib\site-packages\setuptools\command\easy_install.py", line
2245, in main
distclass=DistributionWithoutHelpCommands, **kw
File "C:\Python27\lib\distutils\core.py", line 151, in setup
dist.run_commands()
File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Python27\Lib\site-packages\setuptools\command\easy_install.py", line
380, in run
self.easy_install(spec, not self.no_deps)
File "C:\Python27\Lib\site-packages\setuptools\command\easy_install.py", line
629, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "C:\Python27\Lib\site-packages\setuptools\command\easy_install.py", line
659, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "C:\Python27\Lib\site-packages\setuptools\command\easy_install.py", line
807, in install_eggs
return [self.install_exe(dist_filename, tmpdir)]
File "C:\Python27\Lib\site-packages\setuptools\command\easy_install.py", line
911, in install_exe
'.egg')
File "C:\Python27\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 7: ordinal
not in range(128)
分析原因:
网上搜索资料,讲这是Python 2 mimetypes的bug
解决方法:
修改Python2.7/lib/mimetypes.py文件,添加部分如下所示:
import os
import sys
import posixpath
import urllib
####添加部分如下#####
if sys.getdefaultencoding() != 'gbk':
reload(sys)
sys.setdefaultencoding('gbk')
#################
添加后运行结果:
Installed c:\python27\lib\site-packages\lx
Processing dependencies for lxml
Finished processing dependencies for lxml
有关requests、beautifulsoap4模块的安装说明
http://www.cnblogs.com/kaituorensheng/p/3722913.html
http://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/
本文介绍了在Python2.7环境下安装lxml模块遇到的UnicodeDecodeError错误,并提供了解决方案,通过修改mimetypes.py文件设置默认编码为gbk来避免错误。
4154

被折叠的 条评论
为什么被折叠?



