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

Google Build中从Artifacts Registry安装Python包时遭遇401 Unauthorized错误的授权解决方案咨询

Google Build中从Artifacts Registry安装Python包时遭遇401 Unauthorized错误的授权解决方案咨询

我正在尝试做的事

我想在Google Build里构建一个Docker镜像,这个镜像需要安装一个存储在Artifacts Registry中的Python包,使用的包管理器是uv。

下面是我用来构建镜像的Dockerfile:

FROM python:3.12.2-slim-bookworm

ENV UV_COMPILE_BYTECODE=1
ENV G_PROJECT_ID=...
ENV G_LOCATION=...
ENV G_PY_REPOSITORY=...

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
ADD . /app
WORKDIR /app

RUN uv sync --frozen

RUN uv pip install keyrings.google-artifactregistry-auth
RUN uv pip install --extra-index-url https://$G_LOCATION-python.pkg.dev/$G_PROJECT_ID/$G_PY_REPOSITORY/simple/ my-package --verbose

遇到的问题

在执行uv pip install --extra-index-url这一步时,我收到了401 Unauthorized错误——这其实有点在意料之中,但我实在搞不清楚该怎么完成正确授权。这事儿看起来应该很简单才对。

下面是部分错误输出:

DEBUG No compatible version found for: my-package
  × No solution found when resolving dependencies:
  ╰─▶ Because utils-ms was not found in the package registry and you
      require my-package, we can conclude that your requirements are
      unsatisfiable.

      hint: An index URL
      (https://...-python.pkg.dev/.../.../simple/)
      could not be queried due to a lack of valid authentication credentials
      (401 Unauthorized).
DEBUG Released lock at `/app/.venv/.lock`
The command '/bin/sh -c uv pip install --extra-index-url https://$G_LOCATION-python.pkg.dev/$G_PROJECT_ID/$G_PY_REPOSITORY/simple/ my-package --verbose' returned a non-zero code: 1

相关问题

有一个和我情况非常相似的问题,不过它的错误表现和我的不一样。

备注:内容来源于stack exchange,提问作者Paul Lynn

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 13:39:33