• node-gyp rebuild error【npm install时报错】python


    前言:
    以前老项目安装包的时候报错了,根据报错信息定位到 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51

    通过报错得到的信息

    • 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
    
    • 1
    • 2

    查看python所在位置

    whereis python3
    
    • 1

    设置npm配置python指向

    npm config set python python2.7
    
    • 1

    查看npm配置,主要看python指向问题

    npm config list
    
    • 1

    在这里插入图片描述
    最后就是安装多个版本的python

    python 安装包下载地址:https://www.python.org/downloads(可能需要翻墙,需要私信我)
    参考说明文档 http://t.zoukankan.com/exmyth-p-11185337.html

    根据安装包提示一步步安装就可以了。最后yarn install successful

  • 相关阅读:
    c++作业
    探索AI作画算法的原理:从深度学习到创造性艺术
    Clickhouse—聚合函数组合
    JAVA毕业设计099—基于Java+Springboot+Vue的在线智慧教育考试系统(源码+数据库)
    【5w字】SpringBoot源码分析
    贪心算法归纳
    qiankun 子应用 ant-design-vue快速填坑指南
    React(二):Redux基本使用方法
    MySQL5.7修改默认端口
    匠心新品:大彩科技超薄7寸WIFI线控器发布,热泵、温控器、智能家电首选!
  • 原文地址:https://blog.csdn.net/hqin_520/article/details/125634242