首页 > 解决方案 > GCP - Cloud Function 在同一项目中找不到来自 Artifact Registry 的 Python 包

问题描述

我一直在尝试 GCP 的 Artifact Registry,它目前是 Python 包的 alpha 版本。

如文档中所述,我通过 Keyring 和我的服务帐户进行身份验证。

我可以使用 Twine 成功上传一个包,我可以通过安装以下内容成功将其下载到本地 Python 项目requirements.txt

--extra-index-url https://my-region-pypi.pkg.dev/my-project/my-python-repo/simple/
my-package

但是,当我将最小的 Cloud Function 部署到与我的 Artifact Registry 相同的项目时,requirements.txt如上所示,部署失败并显示以下输出:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: `pip_download_wheels` had stderr output:
ERROR: Could not find a version that satisfies the requirement my-package (from -r requirements.txt (line 2)) (from versions: none)
ERROR: No matching distribution found for my-package (from -r requirements.txt (line 2))

我尝试了两者--extra-index-url并且只是简单--index-url的,没有区别。我还尝试使用以下内容安装密钥环依赖项requirements.txt

--extra-index-url https://my-region-pypi.pkg.dev/my-project/my-python-repo/simple/
keyring
keyrings.google-artifactregistry-auth
my-module

但我得到同样的错误。

我检查了我的项目的默认 App Engine 服务帐户的权限,该帐户也用于 Cloud Functions,并且我可以确认它具有 Artifact Registry Reader 角色,因此这似乎不是权限问题。

我还尝试部署一个最小的 App Engine 服务而不是 Cloud Function,但我得到了同样的错误。

非常感谢您的帮助。

标签: pythongoogle-cloud-platformgoogle-cloud-functionsgoogle-artifact-registry

解决方案


推荐阅读