Anaconda安装后出现utf-8编码错误

报错如下:

Traceback (most recent call last):
  File "E:\Anaconda\AnaConda\Scripts\conda-script.py", line 12, in <module>
    sys.exit(main())
  File "E:\Anaconda\AnaConda\lib\site-packages\conda\cli\main.py", line 145, in main
    init_loggers()
  File "E:\Anaconda\AnaConda\lib\site-packages\conda\cli\main.py", line 56, in init_loggers
    from ..gateways.logging import initialize_logging, set_verbosity
  File "E:\Anaconda\AnaConda\lib\site-packages\conda\gateways\logging.py", line 14, in <module>
    from ..common.io import attach_stderr_handler
  File "E:\Anaconda\AnaConda\lib\site-packages\conda\common\io.py", line 580, in <module>
    class time_recorder(ContextDecorator):  # pragma: no cover
  File "E:\Anaconda\AnaConda\lib\site-packages\conda\common\io.py", line 581, in time_recorder
    record_file = get_instrumentation_record_file()
  File "E:\Anaconda\AnaConda\lib\site-packages\conda\common\io.py", line 577, in get_instrumentation_record_file
    return expand(os.environ.get("CONDA_INSTRUMENTATION_RECORD_FILE", default_record_file))
  File "E:\Anaconda\AnaConda\lib\site-packages\conda\common\path.py", line 49, in expand
    return abspath(expanduser(expandvars(path)))
  File "E:\Anaconda\AnaConda\lib\ntpath.py", line 311, in expanduser
    return userhome + path[i:]
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb5 in position 9: invalid start byte

中文解析错误。上网查找资料后发现是用户目录为中文的原因。
解决方法是:
在E:\Anaconda\AnaConda\lib\ntpath.py文件的join()函数中,添加以下代码:

def join(path, *paths):  
    reload(sys)  
    sys.setdefaultencoding('gbk')  

然后就解决啦!

还尝试了网上的另一种解决方法,我这里没管用:
将conda-scripts.py中的代码替换为以下代码

if __name__ == '__main__':
	import sys
	if sys.getdefaultencoding() != 'gbk': 
		reload(sys) 
	sys.setdefaultencoding('gbk')     
	import conda.cli
	sys.exit(conda.cli.main())
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值