执行pip3 install awscli命令时遇构建依赖错误求助
问题背景
此前执行pip3 install awscli一切正常,但在docker:stable镜像的CI脚本中执行该命令时失败,报错核心为PyYAML构建依赖缺失。
报错信息
Collecting awscli
Downloading awscli-1.29.3-py3-none-any.whl (4.1 MB)
Collecting s3transfer<0.7.0,>=0.6.0
Downloading s3transfer-0.6.1-py3-none-any.whl (79 kB)
Collecting rsa<4.8,>=3.1.2
Downloading rsa-4.7.2-py3-none-any.whl (34 kB)
Collecting PyYAML<5.5,>=3.10
Downloading PyYAML-5.4.1.tar.gz (175 kB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 /usr/lib/python3.8/site-packages/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpvjbfu4r6
原CI脚本
test: image: name: docker:stable before_script: - apk update - apk add curl py-pip jq bash - pip3 install awscli
解决方案
原因分析
docker:stable基于Alpine Linux镜像,默认未安装C语言编译工具链。awscli依赖的PyYAML 5.4.1需要从源码编译生成wheel包,缺少编译依赖会导致构建失败。
修改后的CI脚本
在apk add命令中补充编译所需的依赖包:
test: image: name: docker:stable before_script: - apk update - apk add curl py-pip jq bash gcc python3-dev libffi-dev musl-dev - pip3 install awscli
可选优化
若不想安装完整编译工具链,可跳过构建隔离直接安装PyYAML(仅适配Alpine架构):
pip3 install PyYAML==5.4.1 --no-build-isolation
内容的提问来源于stack exchange,提问作者gcpdev-guy

