记录conda环境升级CUDA相关包后,打开环境终端大段输出或报错

记录工作

直接在stable diffusion webui的conda环境升级CUDA版本后,再打conda虚拟环境后,出现大段报错和输出。

错误示例

例如,我在名为“StableDiffusion”的conda环境,把CUDA11.8升级到CUDA12.3后,打开终端后,出现大段报错和输出:

C:\Users\love>SET DISTUTILS_USE_SDK=1

C:\Users\love>SET MSSdk=1

C:\Users\love>SET "VS_VERSION=16.5"

C:\Users\love>SET "VS_MAJOR=16"

C:\Users\love>SET "VS_YEAR=2019"

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

C:\Users\love>set "MSYS2_ENV_CONV_EXCL=CL"

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

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

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

C:\Users\love>set "VSINSTALLDIR="

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

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

C:\Users\love>if not exist "" (set "VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\" )

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

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

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

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

C:\Users\love>call :GetWin10SdkDir

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

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

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

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

C:\Users\love>if errorlevel 1 exit /B 1

C:\Users\love>exit /B 0

C:\Users\love>for /F %i in ('dir /ON /B "D:\Windows Kits\10\\include"') DO (if NOT "%~i" == "wdf" (SET WindowsSDKVer=%~i ) )

C:\Users\love>(if NOT "10.0.10240.0" == "wdf" (SET WindowsSDKVer=10.0.10240.0 ) )

C:\Users\love>(if NOT "10.0.19041.0" == "wdf" (SET WindowsSDKVer=10.0.19041.0 ) )

C:\Users\love>(if NOT "10.0.20348.0" == "wdf" (SET WindowsSDKVer=10.0.20348.0 ) )

C:\Users\love>(if NOT "10.0.22000.0" == "wdf" (SET WindowsSDKVer=10.0.22000.0 ) )

C:\Users\love>(if NOT "10.0.22621.0" == "wdf" (SET WindowsSDKVer=10.0.22621.0 ) )

C:\Users\love>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: "10.0.22621.0" )
Windows SDK version found as: "10.0.22621.0"

C:\Users\love>IF "win-64" == "win-64" (
set "target_platform=amd64"
 set "CMAKE_GEN=Visual Studio 16 2019 Win64"
 set "BITS=64"
)  else (
set "target_platform=x86"
 set "CMAKE_GEN=Visual Studio 16 2019"
 set "BITS=32"
)

C:\Users\love>pushd C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\
系统找不到指定的路径。

C:\Users\love>set VSCMD_DEBUG=1

C:\Users\love>CALL "VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.2 10.0.22621.0
系统找不到指定的路径。

C:\Users\love>popd

C:\Users\love>IF "" == "" SET "CMAKE_GENERATOR=Visual Studio 16 2019 Win64"

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

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

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

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

C:\Users\love>if errorlevel 1 exit /B 1

C:\Users\love>exit /B 0
Python 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:16:53) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

每次一打开这个conda虚拟环境的终端,就会跳出这一大段报错。

分析原因:

这段脚本看起来是在尝试设置 Visual Studio 的开发环境,并且包含了一些条件判断来确定 Visual Studio 的安装路径。错误信息表明脚本在尝试访问不存在的路径,这可能是因为 Visual Studio 的安装路径不正确,或者脚本中的某些部分与您的实际安装环境不匹配。

要解决这个问题,您可以尝试以下步骤:

1. **确认 Visual Studio 安装路径**:
   - 确保您的 Visual Studio 安装路径与脚本中尝试访问的路径相匹配。如果您的 Visual Studio 安装在 `D:\Program Files\Microsoft Visual Studio\2022\Community`,那么您需要更新脚本中的所有相关路径。

2. **更新脚本中的路径**:
   - 打开脚本文件,查找所有指向旧版本 Visual Studio(如 2019)的路径,并将其替换为 Visual Studio 2022 的实际安装路径。

3. **检查 `vswhere.exe` 的输出**:
   - `vswhere.exe` 是一个工具,用于在系统中查找 Visual Studio 的安装路径。确保 `vswhere.exe` 能够正确地找到 Visual Studio 2022 的安装路径。您可以在命令提示符中直接运行 `vswhere.exe` 来测试它。

4. **检查环境变量**:
   - 确保所有在脚本中设置的环境变量都是正确的,并且与您的系统环境相匹配。

5. **运行脚本时的错误处理**:
   - 如果脚本中的某些部分无法找到正确的路径,您可能需要添加错误处理逻辑,以便在找不到路径时给出更清晰的提示,或者提供一个默认值。

6. **以管理员身份运行**:
   - 确保您以管理员身份运行脚本。在 Windows 搜索栏中输入 `cmd`,右键点击“命令提示符”,然后选择“以管理员身份运行”。

7. **检查 Windows SDK 安装**:
   - 脚本中还尝试查找 Windows SDK 的安装路径。确保您已经安装了 Windows SDK,并且其路径正确无误。

8. **检查 CMake 和其他工具**:
   - 如果脚本中引用了 CMake 或其他构建工具,请确保这些工具已经安装,并且路径设置正确。

如果您不熟悉如何修改脚本,或者在尝试上述步骤后仍然遇到问题,您可能需要寻求一个熟悉 Windows 批处理脚本和 Visual Studio 环境配置的开发者的帮助。您也可以尝试在 Visual Studio 安装器中修复安装,或者重新安装 Visual Studio,以确保所有必要的组件都正确安装。

解决方案:

修改启动脚本文件的内容以匹配路径和调用

找到这个文件:

“vs2019_compiler_vars.bat"

通常这个文件位置conda安装路径下的虚拟环境路径文件夹“envs”下的etc\conda\activate.d\路径

"D:\ProgramData\anaconda3\envs\StableDiffusion\etc\conda\activate.d\vs2019_compiler_vars.bat"

因为我使用的是Visual Studio2022,并且安装路径不是默认的,是被我安装到了D盘的如下路径:

D:\Program Files\Microsoft Visual Studio\2022\Community

修改这个文件:

我使用的是Visual Studio2022,所以我复制了一份“vs2019_compiler_vars.bat"这个文件到其他地方备份

“vs2019_compiler_vars.bat"原文件内容如下:

@echo on
:: Set env vars that tell distutils to use the compiler that we put on path
SET DISTUTILS_USE_SDK=1
:: This is probably not good. It is for the pre-UCRT msvccompiler.py *not* _msvccompiler.py
SET MSSdk=1

SET "VS_VERSION=16.5"
SET "VS_MAJOR=16"
SET "VS_YEAR=2019"

set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out"
set "MSYS2_ENV_CONV_EXCL=CL"

:: For Python 3.5+, ensure that we link with the dynamic runtime.  See
:: http://stevedower.id.au/blog/building-for-python-3-5-part-two/   for more info
set "PY_VCRUNTIME_REDIST=%PREFIX%\bin\vcruntime140.dll"

:: set CC and CXX for cmake
set "CXX=cl.exe"
set "CC=cl.exe"

set "VSINSTALLDIR="
:: Try to find actual vs2017 installations
for /f "usebackq tokens=*" %%i in (`vswhere.exe -nologo -products * -version ^[16.0^,17.0^] -property installationPath`) do (
  :: There is no trailing back-slash from the vswhere, and may make vcvars64.bat fail, so force add it
  set "VSINSTALLDIR=%%i\"
)
if not exist "%VSINSTALLDIR%" (
    :: VS2019 install but with vs2017 compiler stuff installed
	for /f "usebackq tokens=*" %%i in (`vswhere.exe -nologo -products * -requires Microsoft.VisualStudio.Component.VC.v142.x86.x64 -property installationPath`) do (
	:: There is no trailing back-slash from the vswhere, and may make vcvars64.bat fail, so force add it
	set "VSINSTALLDIR=%%i\"
	)
)
if not exist "%VSINSTALLDIR%" (
set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\"
)
if not exist "%VSINSTALLDIR%" (
set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\"
)
if not exist "%VSINSTALLDIR%" (
set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\"
)
if not exist "%VSINSTALLDIR%" (
set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\"
)

IF NOT "%CONDA_BUILD%" == "" (
  set "INCLUDE=%LIBRARY_INC%;%INCLUDE%"
  set "LIB=%LIBRARY_LIB%;%LIB%"
  set "CMAKE_PREFIX_PATH=%LIBRARY_PREFIX%;%CMAKE_PREFIX_PATH%"
)


call :GetWin10SdkDir
:: dir /ON here is sorting the list of folders, such that we use the latest one that we have
for /F %%i in ('dir /ON /B "%WindowsSdkDir%\include"') DO (
  if NOT "%%~i" == "wdf" (
    SET WindowsSDKVer=%%~i
  )
)
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: "%WindowsSDKVer%"
)

IF "win-64" == "win-64" (
  set "target_platform=amd64"
  set "CMAKE_GEN=Visual Studio 16 2019 Win64"
  set "BITS=64"
) else (
  set "target_platform=x86"
  set "CMAKE_GEN=Visual Studio 16 2019"
  set "BITS=32"
)

pushd %VSINSTALLDIR%
set VSCMD_DEBUG=1
CALL "VC\Auxiliary\Build\vcvars%BITS%.bat" -vcvars_ver=14.2 %WindowsSDKVer%
popd

IF "%CMAKE_GENERATOR%" == "" SET "CMAKE_GENERATOR=%CMAKE_GEN%"

:GetWin10SdkDir
call :GetWin10SdkDirHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1
if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1
if errorlevel 1 call :GetWin10SdkDirHelper HKLM\SOFTWARE > nul 2>&1
if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE > nul 2>&1
if errorlevel 1 exit /B 1
exit /B 0


:GetWin10SdkDirHelper
@REM `Get Windows 10 SDK installed folder`
for /F "tokens=1,2*" %%i in ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO (
    if "%%i"=="InstallationFolder" (
        SET WindowsSdkDir=%%~k
    )
)
exit /B 0
需要修改如下内容:

好的,我将指导您如何修改 `vs2019_compiler_vars.bat` 脚本以匹配您的 Visual Studio 2022 Community 版本的配置。请按照以下步骤操作:

1. **打开脚本文件**:
   - 使用文本编辑器(如 Notepad++ 或 Visual Studio Code)打开 `vs2019_compiler_vars.bat` 文件。

2. **更新 Visual Studio 版本信息**:
   - 找到以下行并进行修改:
     ```
     SET "VS_VERSION=16.5"
     SET "VS_MAJOR=16"
     SET "VS_YEAR=2019"
     ```

     SET "VS_VERSION=16.5"
     SET "VS_MAJOR=16"
     SET "VS_YEAR=2019"

     更改为:
     ```
     SET "VS_VERSION=17.0"
     SET "VS_MAJOR=17"
     SET "VS_YEAR=2022"
     ```

     SET "VS_VERSION=17.0"
     SET "VS_MAJOR=17"
     SET "VS_YEAR=2022"

3. **更新 Visual Studio 安装路径**:
   - 找到以下部分并更新路径以匹配您的实际安装路径。假设您的 Visual Studio 2022 安装在 `D:\Program Files\Microsoft Visual Studio\2022\Community`,则需要更改所有相关的路径。
     ```
     if not exist "%VSINSTALLDIR%" (
       set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\"
     )
     ...
     ```

     if not exist "%VSINSTALLDIR%" (
       set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\"
     )
     ...

     更改为:
     ```
     if not exist "%VSINSTALLDIR%" (
       set "VSINSTALLDIR=D:\Program Files\Microsoft Visual Studio\2022\Community\"
     )
     ...
     ```

     if not exist "%VSINSTALLDIR%" (
       set "VSINSTALLDIR=D:\Program Files\Microsoft Visual Studio\2022\Community\"
     )
     ...

4. **更新 vcvars.bat 调用**:
   - 找到以下行并确保 `vcvars%BITS%.bat` 的调用与您的系统架构和 Visual Studio 版本相匹配。
     ```
     CALL "VC\Auxiliary\Build\vcvars%BITS%.bat" -vcvars_ver=14.2 %WindowsSDKVer%
     ```
     如果您的系统是 64 位的,确保 `%BITS%` 被设置为 `64`。

pushd "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\"
set VSCMD_DEBUG=1
CALL vcvarsall.bat x86_amd64
popd

5. **保存并关闭脚本**:
   - 在文本编辑器中保存更改并关闭文件。

6. **测试脚本**:
   - 在 Anaconda Prompt 中激活您的 Conda 环境,然后运行修改后的脚本。您可以通过在命令行中输入脚本的路径来运行它,例如:
     ```cmd
     D:\path\to\your\vs2019_compiler_vars.bat
     ```
     确保替换 `D:\path\to\your\` 为脚本实际所在的路径。

例如在虚拟环境的终端中输入并回车:

"D:\ProgramData\anaconda3\envs\StableDiffusion\etc\conda\activate.d\vs2022_compiler_vars.bat"

请确保替换 `D:\path\to\your\` 为脚本实际所在的路径。 

7. **检查环境变量**:
   - 在 Anaconda Prompt 中输入 `echo %PATH%` 来检查环境变量是否已正确设置。

8. **调试(如果需要)**:
   - 如果在运行脚本时遇到问题,您可以设置 `VSCMD_DEBUG=1` 环境变量来获取更详细的调试信息。这将帮助您诊断问题所在。

请确保在进行任何更改之前备份原始脚本。如果您在修改脚本后遇到任何问题,或者需要进一步的帮助,请提供更多的信息,例如您在运行脚本时遇到的具体错误信息。这将帮助我为您提供更准确的指导。

最后保存退出。

修改后内容示例如下:

@echo off
:: Set env vars that tell distutils to use the compiler that we put on path
SET DISTUTILS_USE_SDK=1
:: This is probably not good. It is for the pre-UCRT msvccompiler.py *not* _msvccompiler.py
SET MSSdk=1

SET "VS_VERSION=17.0"
SET "VS_MAJOR=17"
SET "VS_YEAR=2022"

set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out"
set "MSYS2_ENV_CONV_EXCL=CL"

:: For Python 3.5+, ensure that we link with the dynamic runtime.  See
:: http://stevedower.id.au/blog/building-for-python-3-5-part-two/   for more info
set "PY_VCRUNTIME_REDIST=%PREFIX%\bin\vcruntime140.dll"

:: set CC and CXX for cmake
set "CXX=cl.exe"
set "CC=cl.exe"

set "VSINSTALLDIR=D:\Program Files\Microsoft Visual Studio\2022\Community\"
:: The above line is set to the known VS2022 installation path

IF NOT "%CONDA_BUILD%" == "" (
  set "INCLUDE=%LIBRARY_INC%;%INCLUDE%"
  set "LIB=%LIBRARY_LIB%;%LIB%"
  set "CMAKE_PREFIX_PATH=%LIBRARY_PREFIX%;%CMAKE_PREFIX_PATH%"
)

call :GetWin10SdkDir
:: dir /ON here is sorting the list of folders, such that we use the latest one that we have
for /F %%i in ('dir /ON /B "%WindowsSdkDir%\include"') DO (
  if NOT "%%~i" == "wdf" (
    SET WindowsSDKVer=%%~i
  )
)
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: "%WindowsSDKVer%"
)

IF "win-64" == "win-64" (
  set "target_platform=amd64"
  set "CMAKE_GEN=Visual Studio 17 2022 Win64"
  set "BITS=64"
) else (
  set "target_platform=x86"
  set "CMAKE_GEN=Visual Studio 17 2022"
  set "BITS=32"
)

pushd "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\"
set VSCMD_DEBUG=1
CALL vcvarsall.bat x86_amd64
popd

IF "%CMAKE_GENERATOR%" == "" SET "CMAKE_GENERATOR=%CMAKE_GEN%"

:GetWin10SdkDir
call :GetWin10SdkDirHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1
if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1
if errorlevel 1 call :GetWin10SdkDirHelper HKLM\SOFTWARE > nul 2>&1
if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE > nul 2>&1
if errorlevel 1 exit /B 1
exit /B 0

:GetWin10SdkDirHelper
@REM `Get Windows 10 SDK installed folder`
for /F "tokens=1,2*" %%i in ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO (
    if "%%i"=="InstallationFolder" (
        SET WindowsSdkDir=%%~k
    )
)
exit /B 0

再次打开环境终端:

Windows SDK version found as: "10.0.22621.0"
[DEBUG:vcvarsall.bat] init with arguments 'x86_amd64'
[DEBUG:vcvarsall.bat] Command line parse completed with values:
[DEBUG:vcvarsall.bat] __VCVARSALL_TARGET_ARCH='x64'
[DEBUG:vcvarsall.bat] __VCVARSALL_HOST_ARCH='x86'
[DEBUG:vcvarsall.bat] __VCVARSALL_WINSDK=''
[DEBUG:vcvarsall.bat] __VCVARSALL_STORE=''
[DEBUG:vcvarsall.bat] __VCVARSALL_HELP=''
[DEBUG:vcvarsall.bat] __VCVARSALL_PARSE_ERROR='0'
[DEBUG:VsDevCmd] Writing pre-initialization environment to C:\Users\love\AppData\Local\Temp\dd_vsdevcmd17_preinit_env.log
[DEBUG:core\vsdevcmd_start] initializing with arguments ''
[DEBUG:core\parse_cmd.bat] initializaing with arguments ''
[DEBUG:VsDevCmd.bat] Found version "17.10.0-pre.1.0"
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.10.0-pre.1.0
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[DEBUG:VsDevCmd.bat] calling "core\dotnet.bat"
[DEBUG:core\dotnet.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "core\msbuild.bat"
[DEBUG:core\msbuild.bat] initializing...
[DEBUG:core\msbuild.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "core\winsdk.bat"
[DEBUG:winsdk.bat] initializing...
[DEBUG:core\winsdk.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\clang_cl.bat"
[DEBUG:ext\clang_cl.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\cmake.bat"
[DEBUG:ext\cmake.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\ConnectionManagerExe.bat"
[DEBUG:ext\ConnectionManagerExe.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\diaghub.bat"
[DEBUG:ext\diaghub.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\fsharp.bat"
[DEBUG:ext\fsharp.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\html_help.bat"
[DEBUG:ext\html_help.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\netfxsdk.bat"
[DEBUG:ext\netfxsdk.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\perf_tools.bat"
[DEBUG:ext\perf_tools.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\roslyn.bat"
[DEBUG:ext\roslyn.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\team_explorer.bat"
[DEBUG:ext\team_explorer.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\testwindow.bat"
[DEBUG:ext\testwindow.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\vcpkg.bat"
[DEBUG:ext\vcpkg.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] calling "ext\vcvars.bat"
[DEBUG:ext\vcvars.bat] init:COMPLETE
[DEBUG:VsDevCmd.bat] Sending telemetry
[DEBUG:core\vsdevcmd_end] initializing with arguments ''
[DEBUG:VsDevCmd] Writing post-execution environment to C:\Users\love\AppData\Local\Temp\dd_vsdevcmd17_env.log
[vcvarsall.bat] Environment initialized for: 'x86_x64'

(StableDiffusion) C:\Users\love>

不再报错。

从提供的输出来看,环境设置过程看起来是正常的,没有明显的错误信息。以下是一些关键点的解释:

  1. Windows SDK 版本Windows SDK version found as: "10.0.22621.0" 表示脚本成功地找到了 Windows 10 SDK 的版本号。

  2. Visual Studio 2022 环境初始化[vcvarsall.bat] Environment initialized for: 'x86_x64' 表示 vcvarsall.bat 成功初始化了环境,准备进行 64 位的编译工作。

  3. 调试信息:输出中的 [DEBUG:...] 信息是 Visual Studio 2022 开发者命令提示符的调试信息。这些信息对于开发者来说是有用的,因为它们提供了关于环境初始化过程的详细信息。对于普通用户来说,这些信息表明环境设置过程正在正常进行。

  4. Visual Studio 版本Visual Studio 2022 Developer Command Prompt v17.10.0-pre.1.0 表示我正在使用的是 Visual Studio 2022 的预发布版本。请确保这个版本与你的项目兼容。

  5. Conda 环境(StableDiffusion) 表示我当前激活的 Conda 环境名为 StableDiffusion。这通常意味着我的 Conda 环境已经准备好了,并且包含了所有必要的包和依赖项。

如果你在编译或运行项目时遇到问题,这些调试信息可能会帮助你诊断问题。如果你需要进一步的帮助,请提供具体的错误信息或描述你遇到的问题。

最后也可以重命名文件为“vs2022_compiler_vars.bat”,不影响启动调用。

关闭这些调试输出:

要关闭这些调试输出并直接在 Conda 环境中打开命令提示符,我们需要修改我们的批处理脚本。在脚本中,调试信息是由 `set VSCMD_DEBUG=1` 这行代码启用的。

如果我们想要关闭调试信息,我们需要确保在调用 vcvarsall.bat 时不传递任何参数,因为传递参数(如 x86_amd64)会启用调试模式。在我们的脚本中,我们应该移除或注释掉以下行:

set VSCMD_DEBUG=1
CALL vcvarsall.bat x86_amd64

修改后的脚本应该如下所示:

@echo off
:: ... [省略其他部分] ...

pushd "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\"
CALL vcvarsall.bat
popd

:: ... [省略其他部分] ...

确保在调用 `vcvarsall.bat` 之前没有设置 `VSCMD_DEBUG` 变量。这样,当我们激活 Conda 环境并运行脚本时,它将不会显示调试信息,而是直接显示 `(StableDiffusion) C:\Users\love>` 提示符。

这样,当你运行脚本时,它将不会显示调试信息,而是直接进入 Conda 环境的提示符。

另外,你可以通过在命令行中添加 set VSCMD_DEBUG=0 来关闭调试信息,但这通常在脚本的开始处设置,而不是在调用 vcvarsall.bat 时设置。

请注意,调试信息对于诊断问题非常有用。如果你在编译或运行过程中遇到问题,你可能需要重新启用这些调试信息来帮助定位问题。一旦问题解决,你可以再次关闭它们。

 

保存修改后的脚本,并再次运行它,我们应该会发现调试信息不再显示。如果我们需要调试信息来解决问题,我们可以临时取消注释或添加 `VSCMD_DEBUG=1` 这行代码。

  • 11
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值