You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下构建JAX源码时Bazel无法识别VC++工具求助

Windows下源码构建JAX时Bazel找不到VC++工具的解决方法

我在Windows系统下按官方文档步骤从源码构建JAX,执行python .\build\build.py时触发Bazel编译错误,提示找不到x64架构所需的VCVARSALL.BAT、cl.exe等工具,但我已确认这些工具存在于对应路径,修改环境变量也无效。错误详情如下:

ERROR: C:/users/user/_bazel_user/3fmegsfs/external/flatbuffers/src/BUILD.bazel:53:11: Compiling src/idl_gen_lobster.cpp failed: (Exit 1): vc_installation_error_x64.bat failed: error executing command
  cd /d C:/users/user/_bazel_user/3fmegsfs/execroot/__main__
  SET INCLUDE=msvc_not_found
    SET PATH=msvc_not_found
    SET PWD=/proc/self/cwd
    SET RUNFILES_MANIFEST_ONLY=1
    SET TEMP=msvc_not_found
    SET TMP=msvc_not_found
  external\local_config_cc\vc_installation_error_x64.bat /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /Iexternal/flatbuffers /Ibazel-out/x64_windows-opt/bin/external/flatbuffers /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/src/_virtual_includes/flatc /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/src/_virtual_includes/flatc_library /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/src/_virtual_includes/flatbuffers /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/grpc/src/compiler/_virtual_includes/cpp_generator /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/_virtual_includes/flatbuffers /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/grpc/src/compiler/_virtual_includes/go_generator /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/grpc/src/compiler/_virtual_includes/java_generator /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/grpc/src/compiler/_virtual_includes/python_generator /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/grpc/src/compiler/_virtual_includes/python_generator_private /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/grpc/src/compiler/_virtual_includes/swift_generator /Ibazel-out/x64_windows-opt/bin/external/flatbuffers/grpc/src/compiler/_virtual_includes/ts_generator /showIncludes /MD /O2 /Oy- /DNDEBUG /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" /Gy /Gw /D_USE_MATH_DEFINES -DWIN32_LEAN_AND_MEAN -DNOGDI /Zc:preprocessor -DMLIR_PYTHON_PACKAGE_PREFIX=jaxlib.mlir. /std:c++17 /Fobazel-out/x64_windows-opt/bin/external/flatbuffers/src/_objs/flatc/idl_gen_lobster.obj /c external/flatbuffers/src/idl_gen_lobster.cpp
# Configuration: 55ba85b9103400bcca86968b88fded4983bd3307407d5043544ce61b2cd80103
# Execution platform: @local_execution_config_platform//:platform

The target you are compiling requires Visual C++ build tools.
Bazel couldn't find a valid Visual C++ build tools installation on your machine.

Visual C++ build tools seems to be installed at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x86
But Bazel can't find the following tools:
    VCVARSALL.BAT, cl.exe, link.exe, lib.exe, ml64.exe
for x64 target architecture

Please check your installation following https://docs.bazel.build/versions/main/windows.html#using

Target //build:build_wheel failed to build

解决方法

  • 使用VS开发者命令提示符启动构建
    打开Visual Studio 2022开发者命令提示符(x64),切换到JAX源码所在目录,再执行python .\build\build.py。该提示符会自动配置正确的VC环境变量,规避Bazel的路径识别问题。
  • 手动指定Bazel的VC路径
    在执行构建命令前,通过环境变量明确指定VC工具链的根路径:
    set BAZEL_VC=C:\Program Files\Microsoft Visual Studio\2022\Community\VC
    
    路径需匹配你的VS实际安装目录,确保该路径下包含Tools/MSVC子目录。
  • 升级Bazel到最新稳定版
    部分旧版本Bazel对VS 2022的工具链支持存在兼容性问题,升级后可解决识别错误。
  • 修复VS安装组件
    打开Visual Studio Installer,选择"修改",确认勾选**"C++构建工具"**及对应的x64目标组件,完成修复后重新尝试构建,避免组件缺失导致的工具不可用。

内容的提问来源于stack exchange,提问作者CLeliel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 02:55:28