I am new to python world and I have followed a few articles to set python on my system. I need python to build my project through bazel.
When I build my project on local, I get the following error. Please note, I am able to build the project successfully on server so issue is not related to code.
env: python: No such file or directory
INFO: Elapsed time: 1.708s, Critical Path: 1.09s
INFO: 7 processes: 4 darwin-sandbox, 3 worker.
FAILED: Build did NOT complete successfully
Please HELP ME to solve this issue with my build failure.
I tried to solve this by applying the solutions online but all in vain. I have removed my complete python env and have re-configured it as well but that did not work for me either.
This is my system configuration:
Python version in env is: Python 3.9.12 but it still says "env: python: No such file or directory" in the above error.
└─(13:59:50)──> /usr/bin/env python --version
Python 3.9.12
If I fire /usr/bin/python3 --version I get Python 3.8.9 as output
└─(13:47:35)──> /usr/bin/python3 --version
Python 3.8.9
But when cd
into the /usr/bin/
and I fire python3 --version
command I get Python 3.9.12 as output.
┌─(/usr/bin)──────────────────────────────────────────
└─(13:56:29)──> pwd
/usr/bin
┌─(/usr/bin)──────────────────────────────────────────
└─(13:56:32)──> python3 --version
Python 3.9.12
Also, both /usr/local/bin/python
and /usr/local/bin/python3
point to Python 3.9.12
.
┌─(/usr/bin)──────────────────────────────────────────
└─(13:56:41)──> /usr/local/bin/python --version
Python 3.9.12
┌─(/usr/bin)──────────────────────────────────────────
└─(13:57:46)──> /usr/local/bin/python3 --version
Python 3.9.12
I am having the same issue. Here is what I found. Bazel builds often use
py_binary
tools, which are launched with a shell script that has the shebang#!/usr/bin/env python
(in versions prior to 5). But it also launches them inside a subshell that clears thePATH
environment variable.(exec env - ...)
.This means that there must be a
python
on the system path. Modifying yourPATH
won't help nor will using something likepyenv
. To see which python is being used, run(exec env - python)
. In macOS 12.3, Apple removed/usr/bin/python
. so this fails and printsenv: python: No such file or directory
.I haven't found any way to fix this, since Apple also does not let you modify
/usr/bin
to add a symlink topython3
even as root (due to System Integrity Protection).This is fixed in Bazel 5, but I am not able to upgrade to that since I need to be able to make updates on an older project that has libraries that require Bazel < 4.
Note that Github macOS runners are still on macOS 11. That may be why your project still builds on your server.
I am blocked at this point. I think I either need to find a way to add
python
to the systemPATH
(working around SIP), or I need to back-port some changes from Bazel 5 to Bazel 3 and use a custom version of Bazel. Or I need to do all development and debugging on an older version of macOS.