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应该也能用同样的方法解决。

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

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值