Tensorflow build fails with ModuleNotFoundError: No module named 'six.moves'
@Mathanraj-Sharma You are using an older version of TF which is not actively supported. Could you please check this [doc](https://www.tensorflow.org/install/source#ubuntu) for reference?
Thank you! @sushreebarsa I need that specific version of tf needed to be built, I would appreciate any input/suggestion to overcome this error  @Mathanraj-Sharma You may use the latest TF version 2.15 and let us know?

![68Mw8bzkKTZ4owJ](https://github.com/tensorflow/tensorflow/assets/84765720/1f424915-d380-4fe4-a810-a081798a1467)


Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62970">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62970">No</a>

### Issue type

Build/Install

### Have you reproduced the bug with TensorFlow Nightly?

No

### Source

source

### TensorFlow version

tf 2.4.4

### Custom code

No

### OS platform and distribution

Linux x86_64 CentOS7

### Mobile device

_No response_

### Python version

3.12

### Bazel version

3.1.0

### GCC/compiler version

7.3.1

### CUDA/cuDNN version

-

### GPU model and memory

-

### Current behavior?

I am trying to custom-build tensorflow `2.4.4` for Python 3.12 for a specific use case. I can build it up to Python 3.11 without any issues, but it fails with `ModuleNotFoundError: No module named 'six.moves' ` for 3.12.

I ensured `six` is installed in my python environment, appreciate any help with this

```bash
[root@795834bfc245 tensorflow-2.4.4]# pip list
Package             Version
------------------- -------
Keras-Preprocessing 1.1.2
numpy               1.26.0
pip                 24.0
PyYAML              5.1b5
setuptools          69.1.0
six                 1.16.0
wheel               0.42.0
```

### Standalone code to reproduce the issue

```shell
source /opt/rh/devtoolset-7/enable
wget https://github.com/tensorflow/tensorflow/archive/v2.4.4.tar.gz
tar xf v${TENSORFLOW_VERSION}.tar.gz 
cd tensorflow-2.4.4 
wget -qO-  https://raw.githubusercontent.com/easybuilders/easybuild-easyconfigs/develop/easybuild/easyconfigs/t/TensorFlow/TensorFlow-2.4.0_fix-eigen-on-power.patch  | git apply 
./configure 
BAZEL_LINKLIBS=-l%:libstdc++.a bazel test --host_javabase="@local_jdk//:jdk" --config opt //tensorflow/tools/lib_package:libtensorflow_test
```


### Relevant log output

```shell
[root@795834bfc245 tensorflow-2.4.4]# BAZEL_LINKLIBS=-l%:libstdc++.a bazel test --host_javabase="@local_jdk//:jdk" --config opt //tensorflow/tools/lib_package:libtensorflow_test --verbose_failures --sandbox_debug
Starting local Bazel server and connecting to it...
WARNING: The following configs were expanded more than once: [v2]. For repeatable flags, repeats are counted twice and may lead to unexpected behavior.
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=249
INFO: Reading rc options for 'test' from /tensorflow-2.4.4/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'test' from /tensorflow-2.4.4/.bazelrc:
  Inherited 'build' options: --apple_platform_type=macos --define framework_shared_object=true --define open_source_build=true --java_toolchain=//third_party/toolchains/java:tf_java_toolchain --host_java_toolchain=//third_party/toolchains/java:tf_java_toolchain --define=tensorflow_enable_mlir_generated_gpu_kernels=0 --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --noincompatible_prohibit_aapt1 --enable_platform_specific_config --config=short_logs --config=v2
INFO: Reading rc options for 'test' from /tensorflow-2.4.4/.tf_configure.bazelrc:
  Inherited 'build' options: --action_env PYTHON_BIN_PATH=/root/.pyenv/versions/3.12.1/bin/python3 --action_env PYTHON_LIB_PATH=/root/.pyenv/versions/3.12.1/lib/python3.12/site-packages --python_path=/root/.pyenv/versions/3.12.1/bin/python3 --action_env TF_CONFIGURE_IOS=0
INFO: Reading rc options for 'test' from /tensorflow-2.4.4/.bazelrc:
  'test' options: --define open_source_build=true --config=v2
INFO: Reading rc options for 'test' from /tensorflow-2.4.4/.tf_configure.bazelrc:
  'test' options: --flaky_test_attempts=3 --test_size_filters=small,medium
INFO: Found applicable config definition build:short_logs in file /tensorflow-2.4.4/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /tensorflow-2.4.4/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition test:v2 in file /tensorflow-2.4.4/.tf_configure.bazelrc: --test_tag_filters=-benchmark-test,-no_oss,-gpu,-oss_serial,-v1only --build_tag_filters=-benchmark-test,-no_oss,-gpu,-v1only
INFO: Found applicable config definition build:v2 in file /tensorflow-2.4.4/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition test:v2 in file /tensorflow-2.4.4/.tf_configure.bazelrc: --test_tag_filters=-benchmark-test,-no_oss,-gpu,-oss_serial,-v1only --build_tag_filters=-benchmark-test,-no_oss,-gpu,-v1only
INFO: Found applicable config definition build:opt in file /tensorflow-2.4.4/.tf_configure.bazelrc: --copt=-mtune=generic --host_copt=-mtune=generic --copt=-march=x86-64 --host_copt=-march=x86-64 --copt=-msse --host_copt=-msse --copt=-msse2 --host_copt=-msse2 --copt=-msse3 --host_copt=-msse3 --copt=-msse4.1 --host_copt=-msse4.1 --copt=-msse4.2 --host_copt=-msse4.2 --copt=-mavx --host_copt=-mavx --define with_default_optimizations=true
INFO: Found applicable config definition build:linux in file /tensorflow-2.4.4/.bazelrc: --copt=-w --host_copt=-w --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --config=dynamic_kernels
INFO: Found applicable config definition build:dynamic_kernels in file /tensorflow-2.4.4/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
DEBUG: Rule 'io_bazel_rules_go' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1557349968 -0400"
DEBUG: Repository io_bazel_rules_go instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /root/.cache/bazel/_bazel_root/bb36d39c3ffc7f5337f278aed1ceaa52/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18: in <toplevel>
DEBUG: Rule 'io_bazel_rules_docker' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1556410077 -0400"
DEBUG: Repository io_bazel_rules_docker instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /root/.cache/bazel/_bazel_root/bb36d39c3ffc7f5337f278aed1ceaa52/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18: in <toplevel>
INFO: Analyzed target //tensorflow/tools/lib_package:libtensorflow_test (218 packages loaded, 18761 targets configured).
INFO: Found 1 test target...
ERROR: /tensorflow-2.4.4/tensorflow/tools/lib_package/BUILD:71:1: PackageTar tensorflow/tools/lib_package/cheaders.tar failed (Exit 1): build_tar failed: error executing command 
  (cd /root/.cache/bazel/_bazel_root/bb36d39c3ffc7f5337f278aed1ceaa52/execroot/org_tensorflow && \
  exec env - \
    LD_LIBRARY_PATH=/opt/rh/devtoolset-7/root/usr/lib64:/opt/rh/devtoolset-7/root/usr/lib:/opt/rh/devtoolset-7/root/usr/lib64/dyninst:/opt/rh/devtoolset-7/root/usr/lib/dyninst:/opt/rh/devtoolset-7/root/usr/lib64:/opt/rh/devtoolset-7/root/usr/lib \
    PATH=/opt/rh/devtoolset-7/root/usr/bin:/usr/lib64/ccache:/root/.pyenv/shims:/root/.pyenv/bin:/usr/local/llvm/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PYTHON_BIN_PATH=/root/.pyenv/versions/3.12.1/bin/python3 \
    PYTHON_LIB_PATH=/root/.pyenv/versions/3.12.1/lib/python3.12/site-packages \
    TF2_BEHAVIOR=1 \
    TF_CONFIGURE_IOS=0 \
  bazel-out/host/bin/external/bazel_tools/tools/build_defs/pkg/build_tar --flagfile bazel-out/k8-opt/bin/tensorflow/tools/lib_package/cheaders.args)
Execution platform: @local_execution_config_platform//:platform
Traceback (most recent call last):
  File "/root/.cache/bazel/_bazel_root/bb36d39c3ffc7f5337f278aed1ceaa52/execroot/org_tensorflow/bazel-out/host/bin/external/bazel_tools/tools/build_defs/pkg/build_tar.runfiles/bazel_tools/tools/build_defs/pkg/build_tar.py", line 24, in <module>
    from absl import app
  File "/root/.cache/bazel/_bazel_root/bb36d39c3ffc7f5337f278aed1ceaa52/execroot/org_tensorflow/bazel-out/host/bin/external/bazel_tools/tools/build_defs/pkg/build_tar.runfiles/bazel_tools/third_party/py/abseil/absl/app.py", line 38, in <module>
    from absl import flags
  File "/root/.cache/bazel/_bazel_root/bb36d39c3ffc7f5337f278aed1ceaa52/execroot/org_tensorflow/bazel-out/host/bin/external/bazel_tools/tools/build_defs/pkg/build_tar.runfiles/bazel_tools/third_party/py/abseil/absl/flags/__init__.py", line 40, in <module>
    from absl.flags import _argument_parser
  File "/root/.cache/bazel/_bazel_root/bb36d39c3ffc7f5337f278aed1ceaa52/execroot/org_tensorflow/bazel-out/host/bin/external/bazel_tools/tools/build_defs/pkg/build_tar.runfiles/bazel_tools/third_party/py/abseil/absl/flags/_argument_parser.py", line 29, in <module>
    from absl.flags import _helpers
  File "/root/.cache/bazel/_bazel_root/bb36d39c3ffc7f5337f278aed1ceaa52/execroot/org_tensorflow/bazel-out/host/bin/external/bazel_tools/tools/build_defs/pkg/build_tar.runfiles/bazel_tools/third_party/py/abseil/absl/flags/_helpers.py", line 38, in <module>
    from six.moves import range  # pylint: disable=redefined-builtin
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'six.moves'
----------------
Note: The failure of target @bazel_tools//tools/build_defs/pkg:build_tar (with exit code 1) may have been caused by the fact that it is a Python 2 program that was built in the host configuration, which uses Python 3. You can change the host configuration (for the entire build) to instead use Python 2 by setting --host_force_python=PY2.

If this error started occurring in Bazel 0.27 and later, it may be because the Python toolchain now enforces that targets analyzed as PY2 and PY3 run under a Python 2 and Python 3 interpreter, respectively. See https://github.com/bazelbuild/bazel/issues/7899 for more information.
----------------
Target //tensorflow/tools/lib_package:libtensorflow_test failed to build
INFO: Elapsed time: 164.994s, Critical Path: 51.27s
INFO: 2782 processes: 2782 local.
FAILED: Build did NOT complete successfully
//tensorflow/tools/lib_package:libtensorflow_test               FAILED TO BUILD

FAILED: Build did NOT complete successfully
```
