/usr/bin/env: 'python3': No such file or directory
Hello, thank you for having the time to submitting this issue. One possible way to solve this problem is by installing "python-is-python3" in Ubuntu by running the code `sudo apt update; sudo apt install python-is-python3`. This solved the issue for me. However, even if it worked for me, I can't assure it will work for you as well. I'm just providing you with educational information, I take no responsability. Please, remember that changing the default Python version may have unintended consequences for your system.

Do research on your own before taking action on anything. Here are some sources you can check out that helped me solve this problem myself: [1](https://askubuntu.com/questions/1296790/python-is-python3-package-in-ubuntu-20-04-what-is-it-and-what-does-it-actually); [2](https://linuxpip.org/python-is-python3/); [3](https://askubuntu.com/questions/1440678/purpose-of-python-is-python3).

I hope this serves you well, I wish you a wonderful day!
 I don't have sudo privileges on this system so unfortunately that's not an option for me.  I see. Since you don't have sudo privileges on the system, I think a valid alternative would be to create a virtual environment using the following commands in a terminal: `python3 -m venv venv source venv/bin/activate`. This will create a virtual environment called venv and activate it. You can then install any packages you need using pip, such as boto or openvpn. You can also run python scripts that use `/usr/bin/env` python without errors, as the virtual environment will use the python version in `venv/bin/python`.

Have you already tried this? For context, I'm maintaining the build recipe for TF for the [Spack](https://spack.io) package manager. We want to build from source so we can optimize the build for the exact CPU microarchitecture and GPU model on our supercomputers. So using pip to install pre-compiled wheels is also not an option. @dante-tech the issue is a problem with Tensorflow, it's not a system issue.

Tensorflow unsets PATH before executing a script with shebang `#!/usr/bin/env python3`

Than means it requires a system dependency `/usr/bin/python3`.

That's should never be assumed to exist.

At the same time the build system allows passing `PYTHON_BIN_PATH`, which is ignored. @haampie, I see, thank you to have taken the time to clarify the problem. I will look more into that, and, hopefully, find a solution. @dante-tech it looks like you are GPT4, correct?

Can an actual Tensorflow developer look at this issue? @haampie GPT4? Ahahahahh, I'm just trying to be kind and helpful. Duplicate of #62497 Closing as a duplicate 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/62500">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/62500">No</a>

### Issue type

Build/Install

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

No

### Source

source

### TensorFlow version

2.15.0

### Custom code

No

### OS platform and distribution

Linux Ubuntu 22.04

### Mobile device

_No response_

### Python version

3.11.6

### Bazel version

6.1.0

### GCC/compiler version

11.3.0

### CUDA/cuDNN version

N/A

### GPU model and memory

N/A

### Current behavior?

Towards the end of the build process it crashes with:
```
[14,337 / 14,358] Compiling tensorflow/python/framework/proto_comparators.cc; 7s local ... (12 actions, 11 running)
ERROR: /tmp/root/spack-stage/spack-stage-py-tensorflow-2.15.0-xg7ygjwh7z2ux4a4ozaiwpqnrdu33g2j/spack-src/tensorflow/python/distribute/BUILD:214:18: Extracting tensorflow APIs for //tensorflow/python/distribute:distribute_config to bazel-out/k8-opt/bin/tensorflow/python/distribute/distribute_config_extracted_tensorflow_api.json. failed: (Exit 127): main failed: error executing command (from target //tensorflow/python/distribute:distribute_config) 
  (cd /tmp/spack7c01y2cw/7ef5423ae2652e6ab0e0367d007b4ffb/execroot/org_tensorflow && \
  exec env - \
  bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/python/tools/api/generator2/extractor/main --output bazel-out/k8-opt/bin/tensorflow/python/distribute/distribute_config_extracted_tensorflow_api.json --decorator tensorflow.python.util.tf_export.tf_export --api_name tensorflow tensorflow/python/distribute/distribute_config.py)
# Configuration: 758a0b8a2b418890cf5bce389d31d024017db7b474e9f8dfd2813d4ddd8fb235
# Execution platform: @local_execution_config_platform//:platform
/usr/bin/env: 'python3': No such file or directory
Target //tensorflow/tools/pip_package:build_pip_package failed to build
ERROR: /tmp/root/spack-stage/spack-stage-py-tensorflow-2.15.0-xg7ygjwh7z2ux4a4ozaiwpqnrdu33g2j/spack-src/tensorflow/lite/python/BUILD:72:17 Middleman _middlemen/tensorflow_Slite_Spython_Stflite_Uconvert-runfiles failed: (Exit 127): main failed: error executing command (from target //tensorflow/python/distribute:distribute_config) 
  (cd /tmp/spack7c01y2cw/7ef5423ae2652e6ab0e0367d007b4ffb/execroot/org_tensorflow && \
  exec env - \
  bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/python/tools/api/generator2/extractor/main --output bazel-out/k8-opt/bin/tensorflow/python/distribute/distribute_config_extracted_tensorflow_api.json --decorator tensorflow.python.util.tf_export.tf_export --api_name tensorflow tensorflow/python/distribute/distribute_config.py)
# Configuration: 758a0b8a2b418890cf5bce389d31d024017db7b474e9f8dfd2813d4ddd8fb235
# Execution platform: @local_execution_config_platform//:platform
INFO: Elapsed time: 6724.423s, Critical Path: 384.31s
INFO: 14355 processes: 1147 internal, 13208 local.
FAILED: Build did NOT complete successfully
```
The problem is that Ubuntu 22.04 does not have a `/usr/bin/python3`, only `/usr/bin/python`. I have `python3` installed and in my `PATH`, but the use of `env -` ignores the `PATH` environment variable. I don't see where `env -` is defined so I can't comment it out or replace it.

### Standalone code to reproduce the issue

Build TensorFlow 2.15.0 on Ubuntu 22.04 when `/usr/bin/python3` is not installed but `python3` is in `PATH`.

### Relevant log output

* [build log](https://github.com/tensorflow/tensorflow/files/13501082/spack-build-out.txt)
* [build env](https://github.com/tensorflow/tensorflow/files/13501081/spack-build-env-mods.txt)
