Troubleshoot PyPI package installation

Managed Airflow (Gen 3) | Managed Airflow (Gen 2) | Managed Airflow (Legacy Gen 1)

This page explains how to troubleshoot dependency conflicts when installing custom PyPI packages.

The most common problem with PyPI packages that you might encounter in Managed Airflow are dependency conflicts.

When you specify a new custom PyPI package to install, this package or its version might cause dependency conflicts with other custom PyPI packages or preinstalled packages in your environment. In this case, the environment update operation fails with an error.

Cloud Build and in-cluster build errors

If a problem with packages occurs, you get the error message about it in two ways, depending on the way your environment is deployed:

  • Cloud Build. An error message and a link to the Cloud Build log. For example:

    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 ...
    
  • In-cluster builds. An error message and the location of build logs. For example:

    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.
    

See the detailed error message

When a package installation fails, pip reports the detailed error message. You can find this error message in the build logs.

Locate the pip error in Cloud Build logs

You can follow the link from the Cloud Build error message, or locate build logs:

  1. Locate build logs:

    1. In Google Cloud console, go to the Build history page.

      Go to Build history

    2. Select the failed build to see its logs.

  2. In the build log, find the error message from pip. For example:

    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.
    

Locate the pip error in in-cluster build logs

  1. Locate build logs:

    1. In Google Cloud console, go to the Environments page.

      Go to Environments

    2. Select your environment.

    3. Open the Logs tab.

    4. Select All logs > Composer logs > Builds > Worker & Scheduler image.

    5. In the Severity drop-down list, select Info.

  2. In the displayed logs:

    1. Locate the installer.sh error message. For example:

      The command '/bin/sh -c bash installer.sh $COMPOSER_PYTHON_VERSION
      fail' returned a non-zero code: 1
      
    2. The preceding info messages have the detailed pip error. For example:

      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.
      

Timeouts during Python package installation

In recent versions, the pip utility changed its behavior when attempting to satisfy dependencies. If specified dependencies can't be satisfied, pip goes through all available versions of a package.

When you install a package, the following happens:

  1. If the package is already preinstalled in your environment and Python dependencies that you specify don't require any changes, the package remains as it is.

    Example: aiodebug==2.3.0 is installed and you specify aiodebug or aiodebug>=2.

  2. If the package isn't already installed in your environment or it doesn't satisfy Python dependencies you specify, then pip tries to use the latest version that satisfies dependencies. This is either the latest version of the package if you didn't specify a version, or the latest version of the package that satisfies the specified restrictions.

    Example: If you specify aiodebug, then the latest will be installed (2.*.*). If you specify aiodebug<2, then 1.*.* will be installed.

    If this version causes dependency conflicts with preinstalled packages, pip goes through all available versions of the package to try to satisfy the specified dependency. When it happens, the following messages will be visible in the build log:

    INFO: pip is looking at multiple versions of PYTHON_PACKAGE_NAME
    to determine which version is compatible with other requirements.
    This could take a while.
    

    Before the change, pip failed with a dependency conflict without checking other versions.

Going through all available versions can take a significant amount of time and lead to a downgrade of packages or to a timeout during the Python package installation.

Preinstalled packages in Managed Airflow are regularly updated to the latest versions for security reasons. Therefore, a timeout can also occur when you upgrade an environment to a later Managed Airflow version.

Possible solutions:

  • Regularly update custom Python dependencies.

  • Use PythonVirtualenvOperator to isolate code snippets that require conflicting packages.

Conflicts with preinstalled PyPI packages

Some package conflicts occur between custom PyPI packages that you install and the preinstalled packages.

You can see the full list of preinstalled packages for your version of Managed Airflow on the Managed Airflow versions page.

To solve this problem, you can:

Metadata server unavailable when installing PyPI packages

If your environment uses a custom pip.conf file, then you might face a problem when no new PyPI packages can be installed in your environment. In Cloud Build logs related to the package installation error, you can see the following warning message:

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.

This problem is caused by a pip.conf file that does not allow access to the default package index at https://pypi.org/simple. For example, if your pip.conf file only permits installing packages from a custom Artifact Registry repository because of the redefined index-url parameter, installing packages from the default package index is not available.

To solve this problem, make sure that https://pypi.org/simple package index is added to your pip.conf file. For example, if your primary package index is defined in the index-url parameter, add the https://pypi.org/simple index in the extra-index-url parameter.

Invalid PEP 440 version specifiers

In Managed Airflow (Gen 3) builds starting from composer-3-airflow-3.3.1-build.8, composer-3-airflow-3.2.2-build.12, and composer-3-airflow-2.11.1-build.25, and in Managed Airflow (Gen 2) versions starting from composer-2.18.0-airflow-2.11.1, pip enforces PEP 440 compliance for version specifiers.

The .* wildcard is supported only with == and !=. Package installation or environment upgrades fail if a custom PyPI package requirement uses .* with other version specifier operators, such as >=, <=, >, <, or ~=.

Symptoms

The following error is generated (the package name and version might be different):

ERROR: Invalid requirement: 'gcsfs>=0.8.*': .* suffix can only be used with == or != operators

Solution

To solve this problem, update your custom PyPI package requirements to remove .* from non-equality version specifiers, or use == or != with .*. For example, replace gcsfs>=0.8.* with gcsfs>=0.8.

Isolated source build failures from a private repository

In Managed Airflow (Gen 3) builds starting from composer-3-airflow-3.3.1-build.8, composer-3-airflow-3.2.2-build.12, and composer-3-airflow-2.11.1-build.25, and in Managed Airflow (Gen 2) versions starting from composer-2.18.0-airflow-2.11.1, pip builds .tar.gz source packages in an isolated environment. In this environment, pip can't use build tools already installed in your Managed Airflow environment (such as setuptools or other build dependencies). Instead, pip attempts to download build dependencies from the configured index.

If your environment installs .tar.gz source packages from a private or custom repository configured as your only package index, the build fails when pip can't fetch required build dependencies from that repository.

Symptoms

The following error is generated (the package name and version might be different):

ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none) / No matching distribution found for setuptools>=40.8.0

Solution

To solve this problem, use one of the following options:

  • Add precompiled wheel packages (.whl) for setuptools and any other build dependencies listed under [build-system] requires in the package's pyproject.toml file to your repository.
  • Publish your packages as precompiled .whl packages instead of .tar.gz source packages.
  • As a temporary workaround to disable build isolation, add no-build-isolation = false to the [global] section of your pip.conf file:

    [global]
    no-build-isolation = false
    

    This workaround works only if the build dependencies are already installed in your environment, and it doesn't resolve build failures caused by the legacy pkg_resources module.

For more information, see Isolated source builds.

Build failures for legacy pkg_resources source packages

In Managed Airflow (Gen 3) builds starting from composer-3-airflow-3.3.1-build.8, composer-3-airflow-3.2.2-build.12, and composer-3-airflow-2.11.1-build.25, and in Managed Airflow (Gen 2) versions starting from composer-2.18.0-airflow-2.11.1, source packages that rely on the legacy pkg_resources module might fail to build.

Symptoms

The following error is generated:

ModuleNotFoundError: No module named 'pkg_resources'

Solution

To solve this problem, use one of the following options:

  • For third-party packages, use later package versions that provide precompiled .whl packages.
  • For your own private packages, build them as .whl packages or update their build scripts so that they don't use the legacy pkg_resources module.

What's next