在 mac pro m1 上,“npm install”在使用“env: python: No such file or directory”进行 node-gyp 重建时失败

San*_* Hp 8 javascript node.js npm node-gyp

我正在尝试执行 npm install 并且在我的应用程序中收到错误

系统详细信息:macOS Monterey:版本 12.5

苹果M1 pro芯片

节点版本:14.19.3

节点 gyp 版本:9.1.0

蟒蛇版本: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
 
Run Code Online (Sandbox Code Playgroud)

Tin*_*ky_ 16

问题是 macos 12 中缺少默认的 python。Npm 实际上告诉你

env: python: 没有这样的文件或目录

要解决这个问题,您需要创建一个 python 符号链接,如下所示:

对于自制安装的 python3:

ln -s "$(brew --prefix)/bin/python"{3,}
Run Code Online (Sandbox Code Playgroud)

对于任何 python3:

ln -s "$(which python3)"{3,}
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅:https://namespaceit.com/blog/env-python-no-such-file-or-directory-when-building-app-with-xcode


Khe*_*mbo 0

npm install 抱怨它在环境中找不到 python。要确认是这种情况,请运行以下命令

python --version
Run Code Online (Sandbox Code Playgroud)

您应该收到命令未找到异常。要解决安装 python 的问题,然后运行上述命令将告诉您安装的 python 版本。某些版本的 python 的二进制名称略有不同,例如 python3,因此我建议您安装pyenv,它可用于管理多个版本的 python。按照README中的说明安装 pyenv 和 python。一旦上一个命令返回 python 版本,您就可以再次尝试“npm install”。