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

使用vcpkg构建libtorch失败求助

问题:vcpkg安装libtorch构建失败

环境信息

  • 系统:Windows 10
  • Python:3.8
  • Visual Studio:2019

已尝试操作

  • 克隆vcpkg仓库并完成安装
  • 执行命令:vcpkg.exe install libtorch:x64-windows,后续追加--clean-after-build参数重试

完整错误日志

G:\VCPKG\vcpkg>vcpkg.exe install libtorch:x64-windows --clean-after-build
Computing installation plan...
The following packages will be built and installed:
libtorch[core,xnnpack]:x64-windows -> 1.12.1#2
Detecting compiler hash for triplet x64-windows...
Restored 0 package(s) from C:\Users\Javad\AppData\Local\vcpkg\archives in 17.7 ms. Use --debug to see more details.
Installing 1/1 libtorch:x64-windows...
Building libtorch[core,xnnpack]:x64-windows...
-- Using cached pytorch-pytorch-v1.12.1.tar.gz.
-- Cleaning sources at G:/VCPKG/vcpkg/buildtrees/libtorch/src/v1.12.1-d15308d103.clean. Use --editable to skip cleaning for the packages you specify.
-- Extracting source G:/VCPKG/vcpkg/downloads/pytorch-pytorch-v1.12.1.tar.gz
-- Applying patch pytorch-pr-85958.patch
-- Applying patch fix-cmake.patch
-- Applying patch fix-fbgemm-include.patch
-- Applying patch fix-c10-glog.patch
-- Applying patch use-flatbuffers2.patch
-- Applying patch fix-windows.patch
-- Using source at G:/VCPKG/vcpkg/buildtrees/libtorch/src/v1.12.1-d15308d103.clean
-- Using flatc: G:/VCPKG/vcpkg/installed/x64-windows/tools/flatbuffers/flatc.exe
-- Using protoc: G:/VCPKG/vcpkg/installed/x64-windows/tools/protobuf/protoc.exe
-- Setting up python virtual environmnent...
-- Installing python packages: typing-extensions;pyyaml;numpy
-- Setting up python virtual environmnent...finished.
-- Using Python3: G:/VCPKG/vcpkg/buildtrees/libtorch/x64-windows-venv/Scripts/python.exe
-- Configuring x64-windows-dbg
-- Configuring x64-windows-rel
-- Building x64-windows-dbg
-- Building x64-windows-rel
-- Building x64-windows-dbg
CMake Error at scripts/cmake/vcpkg_execute_build_process.cmake:134 (message):
Command failed: G:/VCPKG/vcpkg/downloads/tools/cmake-3.25.1-windows/cmake-3.25.1-windows-i386/bin/cmake.exe --build . --config Debug --target torch_cpu -- -v -j9
Working Directory: G:/VCPKG/vcpkg/buildtrees/libtorch/x64-windows-dbg
See logs for more information:
G:\VCPKG\vcpkg\buildtrees\libtorch\build-torch_cpu-x64-windows-dbg-out.log

Call Stack (most recent call first):
installed/x64-windows/share/vcpkg-cmake/vcpkg_cmake_build.cmake:74 (vcpkg_execute_build_process)
ports/libtorch/portfile.cmake:157 (vcpkg_cmake_build)
scripts/ports.cmake:147 (include)

error: building libtorch:x64-windows failed with: BUILD_FAILED
Please ensure you're using the latest port files with git pull and vcpkg update.
Then check for known issues at:
https://github.com/microsoft/vcpkg/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+libtorch
You can submit a new issue at:
https://github.com/microsoft/vcpkg/issues/new?title=[libtorch]+Build+error&body=Copy+issue+body+from+G%3A%2FVCPKG%2Fvcpkg%2Finstalled%2Fvcpkg%2Fissue_body.md

问题说明

尝试通过vcpkg为Visual Studio C++安装libtorch,但构建torch_cpu的Debug版本时失败。


解决建议

  1. 查看详细错误日志
    打开G:\VCPKG\vcpkg\buildtrees\libtorch\build-torch_cpu-x64-windows-dbg-out.log,里面会有具体的编译错误(比如依赖缺失、内存不足、代码编译失败等),这是定位问题的核心依据。

  2. 更新vcpkg到最新版
    执行以下命令更新vcpkg及端口文件:

    git pull
    vcpkg update
    

    旧版本的port文件可能存在已修复的构建bug。

  3. 减少并行构建数
    日志中用了-j9并行编译,可能因CPU负载过高或内存不足导致失败,尝试降低并行数:

    vcpkg.exe install libtorch:x64-windows --clean-after-build --parallel=4
    
  4. 检查Visual Studio组件
    打开Visual Studio Installer,确认已安装C++桌面开发组件,以及对应版本的Windows SDK(推荐Windows 10 SDK 19041及以上)。

  5. 尝试禁用XNNPACK或更换版本
    尝试安装不带XNNPACK的libtorch,或者指定更新的版本:

    # 安装仅核心功能的libtorch
    vcpkg.exe install libtorch[core]:x64-windows --clean-after-build
    # 安装1.13.1版本
    vcpkg.exe install libtorch:x64-windows --clean-after-build --version=1.13.1
    
  6. 清理缓存后重建
    删除libtorch相关的构建缓存和下载文件,再重新安装:

    rmdir /s /q G:\VCPKG\vcpkg\buildtrees\libtorch
    rmdir /s /q G:\VCPKG\vcpkg\downloads\pytorch-*
    vcpkg.exe install libtorch:x64-windows --clean-after-build
    

内容的提问来源于stack exchange,提问作者Seyed Amirreza Kabodian

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 15:38:24