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

Docker部署AWS Lambda后端遇duckdb 0.7.0不支持PEP 517构建问题

解决DuckDB在AWS Lambda ARM64镜像中Poetry安装的PEP517错误

问题重现

在使用Poetry为AWS Lambda的ARM64 Python 3.9镜像安装依赖时,执行poetry install步骤遇到以下错误:

Note: This error originates from the build backend, and is likely not a problem with poetry but with duckdb (0.7.0) not supporting PEP 517 builds. You can verify this by running 'pip wheel --use-pep517 "duckdb (==0.7.0)"'.

单独执行pip wheel --use-pep517 "duckdb (==0.7.0)"可正常生成wheel文件,但Poetry安装时仍报错,且duckdb 0.7.1版本存在相同问题。

可行解决方案

方案1:先通过pip单独安装DuckDB,再用Poetry安装其余依赖

修改Dockerfile,在Poetry安装前单独安装duckdb,绕过Poetry的PEP517构建流程:

FROM public.ecr.aws/lambda/python:3.9-arm64

ENV POETRY_VERSION=1.4.2

RUN pip install "poetry==$POETRY_VERSION"

WORKDIR ${LAMBDA_TASK_ROOT}
COPY poetry.lock pyproject.toml ${LAMBDA_TASK_ROOT}/

# 先单独安装duckdb,避免Poetry的PEP517构建问题
RUN pip install duckdb==0.7.0

# 安装其余依赖,跳过已安装的duckdb
RUN poetry config virtualenvs.create false && poetry install --no-dev --no-interaction --no-ansi

# 复制函数代码
COPY app.py ${LAMBDA_TASK_ROOT}
COPY scraper_backend ${LAMBDA_TASK_ROOT}/scraper_backend

CMD [ "app.handler" ]

方案2:导出requirements.txt,改用pip安装所有依赖

绕过Poetry,直接用pip管理依赖:

  1. 本地执行命令导出requirements:
poetry export --without-dev --format requirements.txt --output requirements.txt
  1. 修改Dockerfile替换Poetry安装步骤:
FROM public.ecr.aws/lambda/python:3.9-arm64

WORKDIR ${LAMBDA_TASK_ROOT}
COPY requirements.txt ${LAMBDA_TASK_ROOT}/

# 使用pip直接安装所有依赖
RUN pip install --no-cache-dir -r requirements.txt

# 复制函数代码
COPY app.py ${LAMBDA_TASK_ROOT}
COPY scraper_backend ${LAMBDA_TASK_ROOT}/scraper_backend

CMD [ "app.handler" ]

方案3:升级Poetry版本并调整配置

升级Poetry到最新稳定版,修复ARM64环境下的PEP517兼容问题:

FROM public.ecr.aws/lambda/python:3.9-arm64

# 使用最新稳定版Poetry
ENV POETRY_VERSION=1.8.3

RUN pip install "poetry==$POETRY_VERSION"

WORKDIR ${LAMBDA_TASK_ROOT}
COPY poetry.lock pyproject.toml ${LAMBDA_TASK_ROOT}/

# 调整Poetry配置适配ARM64环境
RUN poetry config experimental.system-git-client true && \
    poetry config installer.max-workers 10 && \
    poetry config virtualenvs.create false && \
    poetry install --no-dev --no-interaction --no-ansi

# 复制函数代码
COPY app.py ${LAMBDA_TASK_ROOT}
COPY scraper_backend ${LAMBDA_TASK_ROOT}/scraper_backend

CMD [ "app.handler" ]

原因分析

DuckDB 0.7.x版本在ARM64架构下的PEP517构建逻辑存在兼容性问题,虽然单独pip wheel可以生成包,但Poetry的依赖构建流程会进行额外校验或强制重新构建,触发了该隐藏问题。通过上述方案可绕过Poetry的构建逻辑,直接使用预构建wheel或pip的安装流程。

内容的提问来源于stack exchange,提问作者david backx

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 07:22:44