排查 PyPI 软件包安装问题

Cloud Composer 1 | Cloud Composer 2

本页面介绍如何在安装自定义 PyPI 软件包时排查依赖项冲突。

您在 Cloud Composer 中可能会遇到的 PyPI 软件包最常见问题是依赖项冲突。

当您指定要安装的新自定义 PyPI 软件包时,此软件包或其版本可能会导致与环境中其他自定义 PyPI 软件包或预安装的软件包发生冲突。在这种情况下,环境更新操作将失败并报错。

Cloud Build 和集群内构建错误

如果软件包出现问题,您可以通过两种方式之一获得错误消息,具体取决于环境的部署方式:

  • Cloud Build。一条错误消息和指向 Cloud Build 日志的链接。例如:

    UPDATE operation on this environment failed 25 minutes ago with the
    following error message:
    Failed to install PyPI packages.  Check the Cloud Build log at ...
    
  • 集群内构建。一条错误消息和构建日志的位置。例如:

    UPDATE operation on this environment failed 17 minutes ago with the
    following error message:
    Failed to install PyPI packages.  Check the in-cluster build logs for
    details. They can be found in the Environment logs under the build-log-*
    log name.
    

查看详细错误消息

如果软件包安装失败,pip 会报告详细错误消息。您可以在构建日志中找到此错误消息。

在 Cloud Build 日志中查找 pip 错误

您可以点击 Cloud Build 错误消息中的链接,也可以查找构建日志:

  1. 查找构建日志:

    1. 在 Google Cloud 控制台中,前往构建记录页面。

      转到“构建历史记录”

    2. 选择失败的构建以查看其日志。

  2. 在构建日志中,查找来自 pip 的错误消息。例如:

    ERROR: apache-airflow-backport-providers-google 2021.2.5 has requirement
    google-cloud-logging<3.0.0,>=2.1.1, but you'll have google-cloud-logging
    1.15.0 which is incompatible.
    

在集群内构建日志中查找 pip 错误

  1. 查找构建日志:

    1. 在 Google Cloud 控制台中,转到环境页面。

      转到“环境”

    2. 选择您的环境。

    3. 打开日志标签页。

    4. 依次选择 All Logs > Composer logs > Builds > Worker & Scheduler image

    5. 严重程度下拉列表中,选择信息

  2. 在显示的日志中:

    1. 查找 installer.sh 错误消息。例如:

      The command '/bin/sh -c bash installer.sh $COMPOSER_PYTHON_VERSION
      fail' returned a non-zero code: 1
      
    2. 上述信息消息包含详细的 pip 错误。例如:

      apache-airflow-backport-providers-google 2021.2.5 has requirement
      google-cloud-logging<3.0.0,>=2.1.1, but you have
      google-cloud-logging 1.15.0.
      

与预安装的 PyPI 软件包冲突

您安装的自定义 PyPI 软件包与预安装的软件包之间会发生一些软件包冲突。

您可以在 Cloud Composer 版本页面上查看 Cloud Composer 版本对应的预安装软件包的完整列表。

如需解决此问题,您可以执行以下操作:

安装 PyPI 软件包时,元数据服务器不可用

如果您的环境使用自定义 pip.conf 文件,那么当无法在您的环境中安装新的 PyPI 软件包时,您可能会遇到问题。在与软件包安装错误相关的 Cloud Build 日志中,您可以看到以下警告消息:

WARNING: Compute Engine Metadata server unavailable on attempt 3 of 3. Reason:
timed out
WARNING: Authentication failed using Compute Engine authentication due to
unavailable metadata server.

此问题是由 pip.conf 文件导致的,该文件不允许访问 http://pypi.org/simple 中的默认软件包索引。例如,如果由于重新定义了 index-url 参数,您的 pip.conf 文件仅允许从自定义 Artifact Registry 代码库安装软件包,则无法从默认软件包索引安装软件包。

如需解决此问题,请确保将 http://pypi.org/simple 软件包索引添加到 pip.conf 文件中。例如,如果您的主要软件包索引是在 index-url 参数中定义的,请在 extra-index-url 参数中添加 http://pypi.org/simple 索引。

后续步骤