No such file or directory: 'patchelf' while compiling from source
facing the same issue
### Issue type

Build/Install

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

No

### Source

source

### TensorFlow version

tf 2.16

### Custom code

No

### OS platform and distribution

Ubuntu 22.04.4 LTS

### Mobile device

_No response_

### Python version

3.11

### Bazel version

6.5.0

### GCC/compiler version

clang 17.0.2

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

I was following the instruction from the official TensorFlow [guide](https://www.tensorflow.org/install/source). Everything was setup ad-verbatim from the build guide. I am using the prebuilt `clang+llvm`. 

However when I try to compile, I am getting this error:

```bash
(tfdev-noclang) user@host:/localdisk/user/tensorflow|(r2.16)> bazel build //tensorflow/tools/pip_package/v2:wheel --repo_env=WHEEL_NAME=tensorflow_cpu --verbose_failures
Starting local Bazel server and connecting to it...
INFO: Reading 'startup' options from /localdisk/user/tensorflow/.bazelrc: --windows_enable_symlinks
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=170
INFO: Reading rc options for 'build' from /localdisk/user/tensorflow/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /localdisk/user/tensorflow/.bazelrc:
  'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --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 --features=-force_no_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility
INFO: Found applicable config definition build:short_logs in file /localdisk/user/tensorflow/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /localdisk/user/tensorflow/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:linux in file /localdisk/user/tensorflow/.bazelrc: --host_copt=-w --copt=-Wno-all --copt=-Wno-extra --copt=-Wno-deprecated --copt=-Wno-deprecated-declarations --copt=-Wno-ignored-attributes --copt=-Wno-array-bounds --copt=-Wunused-result --copt=-Werror=unused-result --copt=-Wswitch --copt=-Werror=switch --copt=-Wno-error=unused-but-set-variable --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --config=dynamic_kernels --experimental_guard_against_concurrent_changes
INFO: Found applicable config definition build:dynamic_kernels in file /localdisk/user/tensorflow/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
DEBUG: /localdisk/user/tensorflow/tensorflow/tools/toolchains/python/python_repo.bzl:32:14:
TF_PYTHON_VERSION environment variable was not set correctly; using Python 3.11.

To set Python version, run:
export TF_PYTHON_VERSION=3.11
INFO: Analyzed target //tensorflow/tools/pip_package/v2:wheel (686 packages loaded, 44337 targets configured).
INFO: Found 1 target...
ERROR: /localdisk/user/tensorflow/tensorflow/tools/pip_package/v2/BUILD:265:9: Action tensorflow/tools/pip_package/v2/wheel_house failed: (Exit 1): build_pip_package_py failed: error executing command (from target //tensorflow/tools/pip_package/v2:wheel)
  (cd /localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/execroot/org_tensorflow && \
  exec env - \
  bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/tools/pip_package/v2/build_pip_package_py @bazel-out/k8-opt/bin/tensorflow/tools/pip_package/v2/wheel_house-0.params)
# Configuration: f208c1d5bcafb33cd85fd8b339492cbe2d1cfa863f489f4edcdc5b70bc65aa65
# Execution platform: @local_execution_config_platform//:platform
Traceback (most recent call last):
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/execroot/org_tensorflow/bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/tools/pip_package/v2/build_pip_package_py.runfiles/org_tensorflow/tensorflow/tools/pip_package/v2/build_pip_package.py", line 321, in <module>
    prepare_wheel_srcs(args.headers, args.srcs, args.xla_aot,
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/execroot/org_tensorflow/bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/tools/pip_package/v2/build_pip_package_py.runfiles/org_tensorflow/tensorflow/tools/pip_package/v2/build_pip_package.py", line 196, in prepare_wheel_srcs
    patch_so(srcs_dir)
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/execroot/org_tensorflow/bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/tools/pip_package/v2/build_pip_package_py.runfiles/org_tensorflow/tensorflow/tools/pip_package/v2/build_pip_package.py", line 231, in patch_so
    subprocess.run(["patchelf", "--add-rpath", path,
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/external/python_x86_64-unknown-linux-gnu/lib/python3.11/subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/external/python_x86_64-unknown-linux-gnu/lib/python3.11/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/external/python_x86_64-unknown-linux-gnu/lib/python3.11/subprocess.py", line 1950, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'patchelf'
Target //tensorflow/tools/pip_package/v2:wheel failed to build
INFO: Elapsed time: 626.996s, Critical Path: 303.61s
INFO: 16379 processes: 1413 internal, 14966 local.
FAILED: Build did NOT complete successfully
```

### Standalone code to reproduce the issue

```shell
# Follow everything from the official guide.
# Use the prebuilt clang+llvm
# To build, invoke this command:
(tfdev-noclang) user@host:/localdisk/user/tensorflow|(r2.16)> bazel build //tensorflow/tools/pip_package/v2:wheel --repo_env=WHEEL_NAME=tensorflow_cpu --verbose_failures
```


### Relevant log output

```shell
Starting local Bazel server and connecting to it...
INFO: Reading 'startup' options from /localdisk/user/tensorflow/.bazelrc: --windows_enable_symlinks
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=170
INFO: Reading rc options for 'build' from /localdisk/user/tensorflow/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /localdisk/user/tensorflow/.bazelrc:
  'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --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 --features=-force_no_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility
INFO: Found applicable config definition build:short_logs in file /localdisk/user/tensorflow/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /localdisk/user/tensorflow/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:linux in file /localdisk/user/tensorflow/.bazelrc: --host_copt=-w --copt=-Wno-all --copt=-Wno-extra --copt=-Wno-deprecated --copt=-Wno-deprecated-declarations --copt=-Wno-ignored-attributes --copt=-Wno-array-bounds --copt=-Wunused-result --copt=-Werror=unused-result --copt=-Wswitch --copt=-Werror=switch --copt=-Wno-error=unused-but-set-variable --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --config=dynamic_kernels --experimental_guard_against_concurrent_changes
INFO: Found applicable config definition build:dynamic_kernels in file /localdisk/user/tensorflow/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
DEBUG: /localdisk/user/tensorflow/tensorflow/tools/toolchains/python/python_repo.bzl:32:14:
TF_PYTHON_VERSION environment variable was not set correctly; using Python 3.11.

To set Python version, run:
export TF_PYTHON_VERSION=3.11
INFO: Analyzed target //tensorflow/tools/pip_package/v2:wheel (686 packages loaded, 44337 targets configured).
INFO: Found 1 target...
ERROR: /localdisk/user/tensorflow/tensorflow/tools/pip_package/v2/BUILD:265:9: Action tensorflow/tools/pip_package/v2/wheel_house failed: (Exit 1): build_pip_package_py failed: error executing command (from target //tensorflow/tools/pip_package/v2:wheel)
  (cd /localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/execroot/org_tensorflow && \
  exec env - \
  bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/tools/pip_package/v2/build_pip_package_py @bazel-out/k8-opt/bin/tensorflow/tools/pip_package/v2/wheel_house-0.params)
# Configuration: f208c1d5bcafb33cd85fd8b339492cbe2d1cfa863f489f4edcdc5b70bc65aa65
# Execution platform: @local_execution_config_platform//:platform
Traceback (most recent call last):
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/execroot/org_tensorflow/bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/tools/pip_package/v2/build_pip_package_py.runfiles/org_tensorflow/tensorflow/tools/pip_package/v2/build_pip_package.py", line 321, in <module>
    prepare_wheel_srcs(args.headers, args.srcs, args.xla_aot,
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/execroot/org_tensorflow/bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/tools/pip_package/v2/build_pip_package_py.runfiles/org_tensorflow/tensorflow/tools/pip_package/v2/build_pip_package.py", line 196, in prepare_wheel_srcs
    patch_so(srcs_dir)
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/execroot/org_tensorflow/bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/tools/pip_package/v2/build_pip_package_py.runfiles/org_tensorflow/tensorflow/tools/pip_package/v2/build_pip_package.py", line 231, in patch_so
    subprocess.run(["patchelf", "--add-rpath", path,
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/external/python_x86_64-unknown-linux-gnu/lib/python3.11/subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/external/python_x86_64-unknown-linux-gnu/lib/python3.11/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/localdisk/user/.cache/bazel/_bazel_user/e4eace97acba9979e5f9a9765d32d25e/external/python_x86_64-unknown-linux-gnu/lib/python3.11/subprocess.py", line 1950, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'patchelf'
Target //tensorflow/tools/pip_package/v2:wheel failed to build
INFO: Elapsed time: 626.996s, Critical Path: 303.61s
INFO: 16379 processes: 1413 internal, 14966 local.
FAILED: Build did NOT complete successfully
```
