使用cmd命令窗在conda的虚拟环境中使用pip或者conda命令安装包时,显示如下错误:
ERROR: Command errored out with exit status 3221226505: command: ‘C:\SoftWare\Anaconda\envs\pytorch\python.exe‘ -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"‘"‘C:\\Users\\CRUISE~1\\AppData\\Local\\Temp\\pip-req-build-6wd_bvgm\\setup.py‘"‘"‘; __file__=‘"‘"‘C:\\Users\\CRUISE~1\\AppData\\Local\\Temp\\pip-req-build-6wd_bvgm\\setup.py‘"‘"‘;f=getattr(tokenize, ‘"‘"‘open‘"‘"‘, open)(__file__);code=f.read().replace(‘"‘"‘\r\n‘"‘"‘, ‘"‘"‘\n‘"‘"‘);f.close();exec(compile(code, __file__, ‘"‘"‘exec‘"‘"‘))‘ egg_info --egg-base ‘C:\Users\CRUISE~1\AppData\Local\Temp\pip-req-build-6wd_bvgm\pip-egg-info‘ cwd: C:\Users\CRUISE~1\AppData\Local\Temp\pip-req-build-6wd_bvgm Complete output (4 lines): Fatal Python error: init_sys_streams: can‘t initialize sys standard streams LookupError: unknown encoding: 65001 Current thread 0x00002cec (most recent call first): ---------------------------------------- ERROR: Command errored out with exit status 3221226505: python setup.py egg_info Check the logs for full command output.
由错误可以看出是编码引起的,但是按照网上的方法使用chcp 936(简中)或者65001(UTF-8)都不行,原因应该是python不将65001识别为utf-8,之后使用以下命令解决:
set PYTHONIOENCODING=utf-8