码迷,mamicode.com
首页 > 编程语言 > 详细

Python使用easy-install安装时报UnicodeDecodeError的解决方法

时间:2016-08-07 13:53:43      阅读:657      评论:0      收藏:0      [点我收藏+]

标签:

Python使用easy-install安装时报UnicodeDecodeError的解决方法,有需要的朋友可以参考下。

问题描述:

在使用easy-install安装matplotlib、pyparsing时一直报如下错误:

File "G:\Python27\lib\ntpath.py", line 84, in join
    result_path = result_path + p_path
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xd4 in position 7: ordinal not in range(128)

我的软件环境如下:

Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win
32

我的系统环境如下:

Windows 8.1 64-bit

解决方法:

错误提示表明应该是编码问题。我按照错误提示,对ntpath.py进行了修改,将第84行改为如下:

<pre name="code" class="python">        
     try: result_path = result_path + p_path except UnicodeDecodeError: result_path = result_path.decode(sysencoding).encode(sysencoding) + p_path.decode(sysencoding).encode(sysencoding)

然后在该文件的import语句结束后的位置添加: 

sysencoding = sys.getfilesystemencoding()

解决了安装报错的问题。

附:

除此以外的其他ntpath.py中碰到的UnicodeDecodeError应该也能用同样的方法解决。

不过记得先注释原语句后修改,方便出问题后恢复原样。

Python使用easy-install安装时报UnicodeDecodeError的解决方法

标签:

原文地址:http://www.cnblogs.com/python2016/p/5745980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!