Repository navigation
build will fail if only python3 avaiable #38791
Description
Activity
It's because actions that run Python in our gypfiles directly reference the
pythonexecutable:Line 1661 in e9e851f
'python', Maybe we should do something in GYP to expose
sys.executableas a variable?- addedgypIssues and PRs related to GYP and .gyp or .gypi build files.Issues and PRs related to GYP and .gyp or .gypi build files.pythonPRs and issues that require attention from people who are familiar with Python.PRs and issues that require attention from people who are familiar with Python.
on May 24, 2021 I believe this is only an issue for building with Ninja. With make our configure scripts write out the path to Python as the
PYTHONmake variable viaconfig.mkbut also create a symbolicpythonlink tosys.executableif it's not the same binary aspythonon the PATH and append the directory containing the link to PATH:
Lines 1952 to 1954 in e9e851f
# Not needed for trivial case. Useless when it's a win32 path. if sys.executable != 'python' and ':\\' not in sys.executable: config['PYTHON'] = sys.executable
Lines 1971 to 1976 in e9e851f
# On Windows there's no reason to search for a different python binary. bin_override = None if sys.platform == 'win32' else make_bin_override() if bin_override: config_str = 'export PATH:=' + bin_override + ':$(PATH)\n' + config_str write('config.mk', do_not_edit + config_str)
Lines 1837 to 1868 in e9e851f
def make_bin_override(): if sys.platform == 'win32': raise Exception('make_bin_override should not be called on win32.') # If the system python is not the python we are running (which should be # python 3), then create a directory with a symlink called `python` to our # sys.executable. This directory will be prefixed to the PATH, so that # other tools that shell out to `python` will use the appropriate python which_python = which('python') if (which_python and os.path.realpath(which_python) == os.path.realpath(sys.executable)): return bin_override = os.path.abspath('out/tools/bin') try: os.makedirs(bin_override) except OSError as e: if e.errno != errno.EEXIST: raise e python_link = os.path.join(bin_override, 'python') try: os.unlink(python_link) except OSError as e: if e.errno != errno.ENOENT: raise e os.symlink(sys.executable, python_link) # We need to set the environment right now so that when gyp (in run_gyp) # shells out, it finds the right python (specifically at # https://github.com/nodejs/node/blob/d82e107/deps/v8/gypfiles/toolchain.gypi#L43) os.environ['PATH'] = bin_override + ':' + os.environ['PATH'] return bin_override (FWIW this is also the reason the V8 CI builds fail when Node.js'
configureis run with Python 3 as the override means#!/usr/bin/env pythonends up pointing to the Python 3 binaryconfigurewas run with instead of the defaultpython.)Am I the only one face the same problem after upgrading macos to 12.3?
npm ERR! gyp info using node-gyp@3.5.0 npm ERR! gyp info using node@17.7.1 | darwin | x64 npm ERR! gyp verb command rebuild [] npm ERR! gyp verb command clean [] npm ERR! gyp verb clean removing "build" directory npm ERR! gyp verb command configure [] npm ERR! gyp verb check python checking for Python executable "/usr/bin/python" in the PATH npm ERR! gyp verb `which` failed Error: not found: /usr/bin/pythonnpm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error: Can't find Python executable "/usr/bin/python", you can set the PYTHON env variable.~> echo $PYTHON /usr/local/bin/python3
Found this on testing gcc-11 docker image.