简体   繁体   English

`npm install` 在 node-gyp 重建时失败,`env: python: No such file or directory` on mac pro m1

[英]`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我正在尝试安装 npm 并且我的应用程序中出现错误

System details: macOS Monterey: version 12.5系统详情:macOS Monterey:版本 12.5

chip Apple M1 pro芯片 Apple M1 pro

node version: 14.19.3节点版本:14.19.3

node-gyp version: 9.1.0节点gyp版本:9.1.0

python version:3.8.9 python版本:3.8.9

> snappy@6.3.5 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
 

npm install is complaining that it cannot find python in the environment. npm 安装抱怨在环境中找不到 python。 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.要解决安装 python 的问题,然后运行上述命令将告诉您安装的 python 的版本。 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.某些版本的 python 的二进制名称略有不同,例如 python3,因此我建议您安装pyenv ,它可用于管理 python 的多个版本。 Follow the instructions in the README to install pyenv and python.按照README中的说明安装 pyenv 和 python。 Once the previous command returns the python version you can then try 'npm install' again.一旦前面的命令返回 python 版本,您就可以再次尝试“npm install”。

The issue is the missing default python in macos 12. Npm actually tells you问题是macos 12中缺少默认的python。Npm实际上告诉你

env: python: No such file or directory环境:python:没有这样的文件或目录

To fix this you need to create a python symlink like so:要解决此问题,您需要创建一个 python 符号链接,如下所示:

For homebrew installed python3:对于自制安装的python3:

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

For any python3:对于任何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有关更多信息,请参阅: https://namespaceit.com/blog/env-python-no-such-file-or-directory-when-building-app-with-xcode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM