Sanjay Hp
Sanjay Hp

Reputation: 179

`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
 

Upvotes: 9

Views: 11503

Answers (3)

OSGI Java
OSGI Java

Reputation: 645

Create a Python virtual environment by executing:

    python3 -m venv env 
    source env/bin/activate

Now you should be able to run python --version and re-run your npm install.

Upvotes: 0

Tinky_
Tinky_

Reputation: 569

The issue is the missing default python in macos 12. Npm actually tells you

env: python: No such file or directory

To fix this you need to create a python symlink like so:

For homebrew installed python3:

ln -s "$(brew --prefix)/bin/python"{3,}

For any python3:

ln -s "$(which python3)"{3,}

For more information see: https://namespaceit.com/blog/env-python-no-such-file-or-directory-when-building-app-with-xcode

Upvotes: 15

Khetho Mtembo
Khetho Mtembo

Reputation: 428

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.

Upvotes: 0

Related Questions