llama-cpp-python安装bug:error: subprocess-exited-。scikit-build-core 0.8.2 using CMake 3.28.3 (wheel)

llama-cpp-python安装bug:error: subprocess-exited-。scikit-build-core 0.8.2 using CMake 3.28.3 (wheel)

环境

系统
linux
python 3.10
llama_cpp_python==0.2.55

1 Bug详情

# 导致安装错误的命令
pip install llama-cpp-python
错误信息
Building wheel for llama-cpp-python (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for llama-cpp-python (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [325 lines of output]
      *** scikit-build-core 0.8.2 using CMake 3.28.3 (wheel)
      *** Configuring CMake...
      2024-03-04 17:29:03,943 - scikit_build_core - WARNING - libdir/ldlibrary: /home/zmp/.conda/envs/base_torch_201cu118_cp310/lib/libpython3.10.a is not a real file!
      2024-03-04 17:29:03,943 - scikit_build_core - WARNING - Can't find a Python library, got libdir=/home/zmp/.conda/envs/base_torch_201cu118_cp310/lib, ldlibrary=libpython3.10.a, multiarch=x86_64-linux-gnu, masd=None
      loading initial cache file /tmp/tmpcjlys8ws/build/CMakeInit.txt
      -- The C compiler identification is GNU 4.8.5
      -- The CXX compiler identification is GNU 4.8.5
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Check for working C compiler: /usr/bin/cc - skipped
      -- Detecting C compile features
      -- Detecting C compile features - done
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - done
      -- Check for working CXX compiler: /usr/bin/c++ - skipped
      -- Detecting CXX compile features
      -- Detecting CXX compile features - done
      -- Found Git: /usr/bin/git (found version "1.8.3.1")
      -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
      -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
      -- Check if compiler accepts -pthread
      -- Check if compiler accepts -pthread - yes
      -- Found Threads: TRUE
      -- Warning: ccache not found - consider installing it for faster compilation or disable this warning with LLAMA_CCACHE=OFF
      -- CMAKE_SYSTEM_PROCESSOR: x86_64
      -- x86 detected
      CMake Warning (dev) at CMakeLists.txt:21 (install):
        Target llama has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.
      This warning is for project developers.  Use -Wno-dev to suppress it.
      
      CMake Warning (dev) at CMakeLists.txt:30 (install):
        Target llama has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.
      This warning is for project developers.  Use -Wno-dev to suppress it.
      
      -- Configuring done (1.1s)
      -- Generating done (0.0s)
      -- Build files have been written to: /tmp/tmpcjlys8ws/build
      *** Building project with Ninja...
      Change Dir: '/tmp/tmpcjlys8ws/build'
......
/tmp/pip-install-qpsadbts/llama-cpp-python_6fb3cbcdc9d540c5b4fb53a5f6f8cd97/vendor/llama.cpp/ggml-quants.c:9656:13: 错误:隐式声明函数‘_mm256_set_m128i’ [-Werror=implicit-function-declaration]
                   const __m256i full_signs_1 = _mm256_set_m128i(full_signs_l, full_signs_l);
                   ^
      /tmp/pip-install-qpsadbts/llama-cpp-python_6fb3cbcdc9d540c5b4fb53a5f6f8cd97/vendor/llama.cpp/ggml-quants.c:9656:42: 错误:用‘int’初始化‘__m256i’时类型不兼容
                   const __m256i full_signs_1 = _mm256_set_m128i(full_signs_l, full_signs_l);
                                                ^
      /tmp/pip-install-qpsadbts/llama-cpp-python_6fb3cbcdc9d540c5b4fb53a5f6f8cd97/vendor/llama.cpp/ggml-quants.c:9657:42: 错误:用‘int’初始化‘__m256i’时类型不兼容
                   const __m256i full_signs_2 = _mm256_set_m128i(full_signs_h, full_signs_h);
.......
 ninja: build stopped: subcommand failed.
      
      
      *** CMake build failed
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with 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 projects

错误原因:使用pip install llama-cpp-python安装时,是通过下载源码编译安装的(llama_cpp_python-0.2.55.tar.gz (36.8 MB))。这时候如果系统没有相应的cmake 和 gcc版本,会弹出这个错误。

2 解决方案

根据系统选择官方编译后的whl下载进行离线安装。

官方网址
Releases · abetlen/llama-cpp-python (github.com)

在这里插入图片描述

安装命令例子

pip install llama_cpp_python-0.2.55-cp310-cp310-manylinux_2_17_x86_64.whl

注:官方只是编译了常见的系统,特殊系统还是需要自行编译。

一般不推荐更新公用linux系统的cmake和gcc进行安装,可以通过建立docker镜像,安装相应版本的cmake和gcc(gcc应高于11.0.0,可以为11.3.0)。查看gcc版本:gcc --version

(xinference) PS C:\Windows\system32> pip install llama-cpp-python Collecting llama-cpp-python Using cached llama_cpp_python-0.3.7.tar.gz (66.7 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... done Collecting typing-extensions>=4.5.0 (from llama-cpp-python) Using cached typing_extensions-4.12.2-py3-none-any.whl.metadata (3.0 kB) Collecting numpy>=1.20.0 (from llama-cpp-python) Using cached numpy-2.2.3-cp311-cp311-win_amd64.whl.metadata (60 kB) Collecting diskcache>=5.6.1 (from llama-cpp-python) Using cached diskcache-5.6.3-py3-none-any.whl.metadata (20 kB) Collecting jinja2>=2.11.3 (from llama-cpp-python) Using cached jinja2-3.1.5-py3-none-any.whl.metadata (2.6 kB) Collecting MarkupSafe>=2.0 (from jinja2>=2.11.3->llama-cpp-python) Using cached MarkupSafe-3.0.2-cp311-cp311-win_amd64.whl.metadata (4.1 kB) Using cached diskcache-5.6.3-py3-none-any.whl (45 kB) Using cached jinja2-3.1.5-py3-none-any.whl (134 kB) Using cached numpy-2.2.3-cp311-cp311-win_amd64.whl (12.9 MB) Using cached typing_extensions-4.12.2-py3-none-any.whl (37 kB) Using cached MarkupSafe-3.0.2-cp311-cp311-win_amd64.whl (15 kB) Building wheels for collected packages: llama-cpp-python Building wheel for llama-cpp-python (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for llama-cpp-python (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [306 lines of output] *** scikit-build-core 0.11.0 using CMake 3.31.6 (wheel) *** Configuring CMake... 2025-03-04 00:24:37,103 - scikit_build_core - WARNING - Can't find a Python library, got libdir=None, ldlibrary=None, multiarch=None, masd=None loading initial cache file C:\Users\admin\AppData\Local\Temp\tmphkbm01o4\build\CMakeInit.txt -- Building for: Visual Studio 17 2022 -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.1
03-08
### 解决方案概述 当尝试在 Windows 上通过 `pip` 安装 `llama-cpp-python` 时,如果遇到构建 wheel 失败的问题,并显示错误信息 `subprocess-exited-with-error` 和退出码 `1`,这通常意味着编译过程中出现了问题。这类问题可能源于依赖项缺失、环境配置不当或其他兼容性因素。 ### 可能的原因分析 此类错误经常发生在基于 C/C++ 的 Python 扩展包安装期间,因为这些扩展需要本地编译工具链支持。对于 `llama-cpp-python` 这样的项目来说,其依赖于特定版本的 CMake 来完成构建过程[^3]。 ### 推荐解决方案 #### 方法一:使用预编译二进制文件 最简单的方法之一是从官方渠道获取适用于当前系统的预编译 whl 文件并直接安装: ```bash pip install https://github.com/your-repo-url/releases/download/vX.Y.Z/llama_cpp_python-X.Y.Z-pyXY-none-win_amd64.whl ``` 请注意替换上述 URL 中的具体版本号和架构信息以匹配实际需求。这种方法可以绕过复杂的源码编译流程,从而避免许多潜在的编译器相关问题。 #### 方法二:确保开发工具已正确安装 如果希望继续从源码安装,则需确认 Visual Studio Build Tools 或 MinGW 已经被正确安装并且路径已被加入到系统 PATH 环境变量中。此外还需要保证 scikit-build-core 版本不低于 0.8.2 并且使用的 CMake 至少为 3.28.3 版本。 可以通过以下命令来更新或安装必要的软件包: ```bash pip install --upgrade pip setuptools wheel cmake scikit-build-core ``` 接着再试一次原始的安装指令看看是否能够成功创建轮子文件。 #### 方法三:调整 PIP 配置参数 有时适当修改 PIP 命令的行为也能帮助解决问题。比如增加 `-v` 参数查看更详细的日志输出以便更好地定位问题所在;或者指定临时目录用于存储中间产物防止权限不足引起的问题等。 ```bash pip install llama-cpp-python -v --no-cache-dir --temp-dir ./tmp_build_dir/ ``` 以上措施有助于排除因缓存污染或是磁盘空间不够等原因造成的失败情况。 ### 注意事项 在整个处理过程中应当保持网络连接稳定以免中途下载中断造成不必要的麻烦。另外建议先清理掉之前未成功的构建残留物后再重新开始新的尝试。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值