前言:
以前老项目安装包的时候报错了,根据报错信息定位到 node-gyp版本3.8.0 依赖python2版本
报错信息如下
npm install
npm ERR! code 1
npm ERR! path /Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/node-expat
npm ERR! command failed
npm ERR! command sh -c /var/folders/2k/x8512sqn4qg3h8pwytlch0440000gn/T/install65772552393.sh
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@14.18.3 | darwin | x64
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
npm ERR! gyp ERR! stack at PythonFinder.failNoPython (/Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/node-gyp/lib/configure.js:484:19)
npm ERR! gyp ERR! stack at PythonFinder.<anonymous> (/Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/node-gyp/lib/configure.js:406:16)
npm ERR! gyp ERR! stack at F (/Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/which/which.js:68:16)
npm ERR! gyp ERR! stack at E (/Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/which/which.js:80:29)
npm ERR! gyp ERR! stack at /Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/which/which.js:89:16
npm ERR! gyp ERR! stack at /Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/isexe/index.js:42:5
npm ERR! gyp ERR! stack at /Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/isexe/mode.js:8:5
npm ERR! gyp ERR! stack at FSReqCallback.oncomplete (fs.js:191:21)
npm ERR! gyp ERR! System Darwin 21.5.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/node-expat
npm ERR! gyp ERR! node -v v14.18.3
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/hqin/.npm/_logs/2022-07-06T01_49_57_631Z-debug-0.log
yarn install
error /Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/node-expat: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/node-expat
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.0
gyp info using node@14.18.3 | darwin | x64
gyp info find Python using Python version 3.8.9 found at "/Library/Developer/CommandLineTools/usr/bin/python3"
gyp info spawn /Library/Developer/CommandLineTools/usr/bin/python3
gyp info spawn args [
gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/node-expat/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/Users/hqin/Library/Caches/node-gyp/14.18.3/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/Users/hqin/Library/Caches/node-gyp/14.18.3',
gyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/Users/hqin/Library/Caches/node-gyp/14.18.3/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/node-expat',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmlparse.o
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmltok.o
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmlrole.o
LIBTOOL-STATIC Release/libexpat.a
env: python: No such file or directory
make: *** [Release/libexpat.a] Error 127
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/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:282:12)
gyp ERR! System Darwin 21.5.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/hqin/Desktop/code-zkx/kts-app-discharge-billing/node_modules/node-expat
通过报错得到的信息
- node版本v14.18.3
- node-gyp 3.8.0
- 找到python版本是3.0
- 运行环境是macos
解决办法
1、官方的issues:
github 官方的issues解决办法:npm install -g npm
https://github.com/nodejs/node-gyp/issues/2191
2、安装多个python版本:
查看python版本
python3 --version
python --version
查看python所在位置
whereis python3
设置npm配置python指向
npm config set python python2.7
查看npm配置,主要看python指向问题
npm config list
最后就是安装多个版本的python
python 安装包下载地址:https://www.python.org/downloads(可能需要翻墙,需要私信我)
参考说明文档 http://t.zoukankan.com/exmyth-p-11185337.html
根据安装包提示一步步安装就可以了。最后yarn install successful