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

在VS Code中用pip安装llama-cpp-python时遇编译错误求助

解决llama-cpp-python编译安装失败问题

报错信息

4 条警告
          257 条错误

      耗时 00:00:02.56


      *** CMake构建失败
      [输出结束]

  注意:此错误源自子进程,大概率与pip无关。
  ERROR: Failed building wheel for llama-cpp-python
Failed to build llama-cpp-python
ERROR: Could not build wheels for llama-cpp-python, which is required to install pyproject.toml-based project

解决步骤

1. 补全编译依赖环境

  • Windows:安装Visual Studio,勾选「桌面开发C++」组件,安装完成后重启终端,确保cmake和msbuild可在命令行正常调用
  • Linux:执行以下命令安装基础编译工具:
    sudo apt update && sudo apt install build-essential cmake gcc g++
    
  • macOS:运行xcode-select --install安装Command Line Tools,再用brew install cmake升级CMake版本

2. 直接安装预编译二进制包(推荐)

跳过本地编译环节,使用官方提供的预编译wheel包,根据你的系统执行对应命令:

  • Windows x64:
    pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
    
  • macOS Intel:
    pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/intel
    
  • macOS Apple Silicon:
    pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/arm64
    
  • Linux x86_64:
    pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/linux_x86_64
    

3. 调整编译参数(本地编译场景)

如果必须本地编译,可通过指定编译器或禁用不必要的特性解决:

  • Windows(强制使用VS的cl编译器):
    set CMAKE_C_COMPILER=cl.exe
    pip install llama-cpp-python
    
  • Linux/macOS(指定gcc编译器):
    CMAKE_ARGS="-DCMAKE_C_COMPILER=gcc" pip install llama-cpp-python
    
  • 禁用CUDA加速(减少编译复杂度):
    CMAKE_ARGS="-DLLAMA_CUBLAS=OFF" pip install llama-cpp-python
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 02:34:53