AWS SageMaker安装llama-cpp-python失败:构建wheel出错
解决AWS SageMaker Notebook安装llama-cpp-python==0.1.48失败问题
问题场景
使用AWS SageMaker的ml.g5.2xlarge或ml.g4dn.2xlarge实例运行LLaMA模型(规避Colab Pro 15GB显存限制),但执行!pip install llama-cpp-python==0.1.48时出现编译wheel失败错误:
Building wheel for llama-cpp-python (pyproject.toml) did not run successfully. exit code: 1 [130 lines 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
解决方案
安装编译依赖工具
SageMaker默认环境缺少编译C++扩展的基础库,先执行:!sudo apt-get update && sudo apt-get install -y build-essential cmake libopenblas-dev libomp-dev启用CUDA支持编译
llama-cpp-python需要显式开启CUDA才能适配SageMaker的GPU实例,设置环境变量后再安装:!CMAKE_ARGS="-DLLAMA_CUBLAS=on" FORCE_CMAKE=1 pip install llama-cpp-python==0.1.48升级pip及构建工具(可选)
如果上述步骤仍失败,先升级pip、wheel和setuptools再重试:!pip install --upgrade pip wheel setuptools之后重新执行步骤2的安装命令。
原因说明
- SageMaker Notebook默认未预装编译C扩展所需的
build-essential、cmake等工具,导致无法编译llama-cpp-python的底层C代码。 - 未显式启用CUDA支持时,编译过程无法适配GPU实例的硬件环境,进而触发编译失败。
内容的提问来源于stack exchange,提问作者ku11
相关产品推荐
相关产品推荐

