Search code examples
javascriptnode.jsnpmnode-gyp

`npm install` fails on node-gyp rebuild with `env: python: No such file or directory` on mac pro m1


I am trying to do npm install and I am getting the error in my application

System details: macOS Monterey : version 12.5

chip Apple M1 pro

node version: 14.19.3

node-gyp version: 9.1.0

python version:3.8.9

> [email protected] install /Users/sanhp/client-access-portal/node_modules/snappy
> prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=14.19.3 runtime=node arch=arm64 libc= platform=darwin)
  CXX(target) Release/obj.target/snappy/deps/snappy/snappy-1.1.7/snappy-sinksource.o
  CXX(target) Release/obj.target/snappy/deps/snappy/snappy-1.1.7/snappy-stubs-internal.o
  CXX(target) Release/obj.target/snappy/deps/snappy/snappy-1.1.7/snappy.o
  LIBTOOL-STATIC Release/snappy.a
env: python: No such file or directory
make: *** [Release/snappy.a] Error 127
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/sanhp/.nvm/versions/node/v14.19.3/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:285:12)
gyp ERR! System Darwin 21.6.0
gyp ERR! command "/Users/sanhp/.nvm/versions/node/v14.19.3/bin/node" "/Users/sanhp/.nvm/versions/node/v14.19.3/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/sanhp/client-access-portal/node_modules/snappy
gyp ERR! node -v v14.19.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
 

Solution

  • npm install is complaining that it cannot find python in the environment. To confirm that is the case run the following command

    python --version
    

    You should get a command not found exception. To resolve install python after which running the above command will tell you the version of python installed. Some versions of python have a slightly different binary name for example python3 so I recommend you install pyenv which can be used to manage multiple versions of python. Follow the instructions in the README to install pyenv and python. Once the previous command returns the python version you can then try 'npm install' again.