安装 visual studio 2019 后如何正确激活 anaconda 环境

How to activate anaconda environments properly after installing visual studio 2019

安装 Visual Studio 2019 后,我的 anaconda 出现问题。当我在我的 anaconda 中创建一个新的环境时,几个小时后我在尝试激活环境时遇到了问题,之后当我打开任何 jupyter notebook 时,内核将无法工作。我在激活环境时复制了消息。如何恢复我的 anaconda 环境?我已经卸载了 Visual Studio 并删除了它的所有文件,但问题仍然存在。感谢您为解决此问题提供的任何帮助。我正在使用 Windows 10 和 Anaconda 3。

(base) C:\>conda activate enviro

C:\>SET DISTUTILS_USE_SDK=1

C:\>SET MSSdk=1

C:\>SET "VS_VERSION=15.0"

C:\>SET "VS_MAJOR=15"

C:\>SET "VS_YEAR=2017"

C:\>set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out"

C:\>set "MSYS2_ENV_CONV_EXCL=CL"

C:\>set "PY_VCRUNTIME_REDIST=\bin\vcruntime140.dll"

C:\>set "CXX=cl.exe"

C:\>set "CC=cl.exe"

C:\>set "VSINSTALLDIR="

C:\>for /F "usebackq tokens=*" %i in (`vswhere.exe -nologo -products * -version [15.0,16.0) -property installationPath`) do (set "VSINSTALLDIR=%i\" )

C:\>if not exist "" (for /F "usebackq tokens=*" %i in (`vswhere.exe -nologo -products * -requires Microsoft.VisualStudio.Component.VC.v141.x86.x64 -property installationPath`) do (set "VSINSTALLDIR=%i\" ) )

C:\>if not exist "" (set "VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio17\Professional\" )

C:\>if not exist "C:\Program Files (x86)\Microsoft Visual Studio17\Professional\" (set "VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio17\Community\" )

C:\>if not exist "C:\Program Files (x86)\Microsoft Visual Studio17\Community\" (set "VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\" )

C:\>if not exist "C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\" (set "VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\" )

C:\>IF NOT "" == "" (
set "INCLUDE=;"
 set "LIB=;"
 set "CMAKE_PREFIX_PATH=;"
)

C:\>call :GetWin10SdkDir

C:\>call :GetWin10SdkDirHelper HKLM\SOFTWARE\Wow6432Node  1>nul 2>&1

C:\>if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE\Wow6432Node  1>nul 2>&1

C:\>if errorlevel 1 call :GetWin10SdkDirHelper HKLM\SOFTWARE  1>nul 2>&1

C:\>if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE  1>nul 2>&1

C:\>if errorlevel 1 exit /B 1

C:\>exit /B 0

C:\>for /F %i in ('dir /ON /B "\include.*"') DO (SET WindowsSDKVer=%~i )
The system cannot find the file specified.

C:\>if errorlevel 1 (echo "Didn't find any windows 10 SDK. I'm not sure if things will work, but let's try..." )  else (echo Windows SDK version found as: "" )
Windows SDK version found as: ""

C:\>IF "win-64" == "win-64" (
set "CMAKE_GEN=Visual Studio 15 2017 Win64"
 set "BITS=64"
)  else (
set "CMAKE_GEN=Visual Studio 15 2017"
 set "BITS=32"
)

C:\>pushd C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\
The system cannot find the path specified.

C:\>CALL "VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.16
The system cannot find the path specified.

C:\>popd

C:\>IF "" == "" SET "CMAKE_GENERATOR=Visual Studio 15 2017 Win64"

C:\>call :GetWin10SdkDirHelper HKLM\SOFTWARE\Wow6432Node  1>nul 2>&1

C:\>if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE\Wow6432Node  1>nul 2>&1

C:\>if errorlevel 1 call :GetWin10SdkDirHelper HKLM\SOFTWARE  1>nul 2>&1

C:\>if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE  1>nul 2>&1

C:\>if errorlevel 1 exit /B 1

C:\>exit /B 0

(enviro) C:\>

通过删除 Anaconda3\envs\enviro\etc\conda\activate.d.

中的 vs2017_compiler_vars 文件解决了这个问题