报错如下:
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())