node-gyp: trying to 'npm install', getting node-gyp rebuild and python errors

npm ERR! code 1 npm ERR! path /Users/Petersenrr/dev/qa-brightspot/node_modules/node-expat npm ERR! command failed npm ERR! command sh -c node-gyp rebuild npm ERR! CC(target) Release/obj.target/expat/deps/libexpat/lib/xmlparse.o npm ERR! CC(target) Release/obj.target/expat/deps/libexpat/lib/xmltok.o npm ERR! CC(target) Release/obj.target/expat/deps/libexpat/lib/xmlrole.o npm ERR! LIBTOOL-STATIC Release/libexpat.a npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@7.1.2 npm ERR! gyp info using node@16.4.1 | darwin | x64 npm ERR! gyp info find Python using Python version 3.10.3 found at “/Library/Frameworks/Python.framework/Versions/3.10/bin/python3” npm ERR! (node:11296) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only. npm ERR! (Use node --trace-deprecation ... to show where the warning was created) npm ERR! gyp info spawn /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args ‘/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py’, npm ERR! gyp info spawn args ‘binding.gyp’, npm ERR! gyp info spawn args ‘-f’, npm ERR! gyp info spawn args ‘make’, npm ERR! gyp info spawn args ‘-I’, npm ERR! gyp info spawn args ‘/Users/Petersenrr/dev/qa-brightspot/node_modules/node-expat/build/config.gypi’, npm ERR! gyp info spawn args ‘-I’, npm ERR! gyp info spawn args ‘/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi’, npm ERR! gyp info spawn args ‘-I’, npm ERR! gyp info spawn args ‘/Users/Petersenrr/Library/Caches/node-gyp/16.4.1/include/node/common.gypi’, npm ERR! gyp info spawn args ‘-Dlibrary=shared_library’, npm ERR! gyp info spawn args ‘-Dvisibility=default’, npm ERR! gyp info spawn args ‘-Dnode_root_dir=/Users/Petersenrr/Library/Caches/node-gyp/16.4.1’, npm ERR! gyp info spawn args ‘-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp’, npm ERR! gyp info spawn args ‘-Dnode_lib_file=/Users/Petersenrr/Library/Caches/node-gyp/16.4.1/<(target_arch)/node.lib’, npm ERR! gyp info spawn args ‘-Dmodule_root_dir=/Users/Petersenrr/dev/qa-brightspot/node_modules/node-expat’, npm ERR! gyp info spawn args ‘-Dnode_engine=v8’, npm ERR! gyp info spawn args ‘–depth=.’, npm ERR! gyp info spawn args ‘–no-parallel’, npm ERR! gyp info spawn args ‘–generator-output’, npm ERR! gyp info spawn args ‘build’, npm ERR! gyp info spawn args ‘-Goutput_dir=.’ npm ERR! gyp info spawn args ] npm ERR! gyp info spawn make npm ERR! gyp info spawn args [ ‘BUILDTYPE=Release’, ‘-C’, ‘build’ ] npm ERR! env: python: No such file or directory npm ERR! make: *** [Release/libexpat.a] Error 127 npm ERR! gyp ERR! build error npm ERR! gyp ERR! stack Error: make failed with exit code: 2 npm ERR! gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:394:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12) npm ERR! gyp ERR! System Darwin 21.5.0 npm ERR! gyp ERR! command “/usr/local/bin/node” “/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “rebuild” npm ERR! gyp ERR! cwd /Users/Petersenrr/dev/qa-brightspot/node_modules/node-expat npm ERR! gyp ERR! node -v v16.4.1 npm ERR! gyp ERR! node-gyp -v v7.1.2 npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in: npm ERR! /Users/Petersenrr/.npm/_logs/2022-06-13T20_02_03_320Z-debug.log

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 38 (14 by maintainers)

Most upvoted comments

Following these steps fixed it for me

brew install pyenv pyenv install --list pyenv install 2.7.18 pyenv versions pyenv global 2.7.18 Put eval “$(pyenv init --path)” in ~/.zprofile (or ~/.bash_profile or ~/.zshrc)

I’ve had the same issue, this worked for me:

  1. If you have python installed via brew – remove it brew remove python
  2. Make sure to remove any aliases for python as well
  3. Install pyenv via brew brew install pyenv
  4. Install the desired version of python for me it was pyenv install 3.9.6
  5. Select the python version using pyenv global 3.9.6
  6. Add the following snippet to your shell config file, for me it was .zshrc
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi
  1. Restart the terminal – try installing packages again, npm install or yarn

These steps are based on the following article I’ve found by searching the solution for the problem, so all the credit goes to the author: https://opensource.com/article/19/5/python-3-default-mac

@yesworld In case if you still have the problem you may want to try this approach.

Not keen on installing pyenv or removing brew’s Python 😅

/usr/bin/env python is looking in your PATH for a python executable. If you’ve installed Python using brew, then it’ll have installed python3 in /opt/homebrew/bin/, but not a simple python alias, eg:

🌵$ which python3
/opt/homebrew/bin/python3
🌵$ which python
🌵$ 

However it has included installed a bunch of symlinks (including python), just not in a directory likely to be in your PATH. On my Mac, that’s: /opt/homebrew/opt/python@3.10/libexec/bin/. You need to put that directory in your PATH, using something like:

export PATH="/opt/homebrew/opt/python@3.10/libexec/bin:$PATH"

in your ~/.profile (and then restart your terminal). You’ll know you’ve got this right when you can type: env python -V and you get back a version string, and which python returns something like:

🌵$ which python
/opt/homebrew/opt/python@3.10/libexec/bin/python

faced the same problem… 😦

$ brew install python
Warning: python@3.9 3.9.12 is already installed and up-to-date.
To reinstall 3.9.12, run:
  brew reinstall python@3.9
npm info node-gyp version
9.3.0

env: python: No such file or directory make: *** [Release/sass.a] Error 127 gyp ERR! build error gyp ERR! stack Error: make failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/…/node_modules/node-gyp/lib/build.js:194:23) gyp ERR! stack at ChildProcess.emit (node:events:527:28) gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) gyp ERR! System Darwin 21.5.0

alias python=/usr/bin/python3 python --version

Petersenrr@RyanPetinch2019 ~ % alias python=/usr/bin/python3
Petersenrr@RyanPetinch2019 ~ % python --version             
Python 3.8.2

@cclauss I don’t think aliases typically apply in programs only directly in shells. Hence why your alias fix probably didn’t work. You could probably make a symbolic link in a directory and add a PATH element to that directory instead if you wanted to avoid breaking other stuff. (Found this issue with Google)

@cclauss I admire your patience reading this issue

@petersenrr you should not really use python2

Python 2 died 897 days ago on 1/1/2020. Current versions of node-gyp no longer support it.

Just do brew install python for current versions of node-gyp.