Rate This Document
Findability
Accuracy
Completeness
Readability

Alarm Reported When Building the TensorFlow pip Software Package

Symptom

An alarm is reported when building the TensorFlow pip software package. Some alarm information is as follows:

!!
  check.warn(importable)
/usr/local/lib/python3.9/site-packages/setuptools/command/build_py.py:204: _Warning: Package 'tensorflow.xla_aot_runtime_src.tensorflow.tsl.platform' is absent from the `packages` configuration.
!!

        ********************************************************************************
        ############################
        # Package would be ignored #
        ############################
        Python recognizes 'tensorflow.xla_aot_runtime_src.tensorflow.tsl.platform' as an importable package[^1],
        but it is absent from setuptools' `packages` configuration.

        This leads to an ambiguous overall configuration. If you want to distribute this
        package, please make sure that 'tensorflow.xla_aot_runtime_src.tensorflow.tsl.platform' is explicitly added
        to the `packages` configuration field.

        Alternatively, you can also rely on setuptools' discovery methods
        (for example by using `find_namespace_packages(...)`/`find_namespace:`
        instead of `find_packages(...)`/`find:`).

        You can read more about "package discovery" on setuptools documentation page:

        - https://setuptools.pypa.io/en/latest/userguide/package_discovery.html

        If you don't want 'tensorflow.xla_aot_runtime_src.tensorflow.tsl.platform' to be distributed and are
        already explicitly excluding 'tensorflow.xla_aot_runtime_src.tensorflow.tsl.platform' via
        `find_namespace_packages(...)/find_namespace` or `find_packages(...)/find`,
        you can try to use `exclude_package_data`, or `include-package-data=False` in
        combination with a more fine grained `package-data` configuration.

        You can read more about "package data files" on setuptools documentation page:

        - https://setuptools.pypa.io/en/latest/userguide/datafiles.html


        [^1]: For Python, any directory (with suitable naming) can be imported,
              even if it does not contain any `.py` files.
              On the other hand, currently there is no concept of package data
              directory, all directories are treated like packages.
        ********************************************************************************

Key Process and Cause Analysis

Key error information: setuptools methods change as the version evolves. Replace find_packages(...) or find: with find_namespace_packages(...) or find_namespace:.

1
Alternatively, you can also rely on setuptools' discovery methods(for example by using `find_namespace_packages(...)`/`find_namespace:`instead of `find_packages(...)`/`find:`).

Root cause analysis: The setuptools version is incompatible.

Conclusion and Solution

  1. Query the current setuptools version.
    1
    pip3 list | grep setuptools
    

    Version information:

  2. Downgrade setuptools.
    1
    2
    pip3 uninstall setuptools
    pip3 install setuptools==56.0.0
    

    Setuptools 56.0.0 is installed successfully.

    It has been verified that alarms can be cleared in setuptools 42.0.2, 50.0.0, 56.0.0 and 57.0.0.

  3. Rebuild the package.
    1
    ./bazel-bin/tensorflow/tools/pip_package/build_pip_package ./output