node-gyp:import sys; print “%s.%s.%s“ % sys.version_info[:3];

使用之前先看官网简介:node-gyp - npm

Node.js native addon build tool

node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js. It contains a vendored copy of the gyp-next project that was previously used by the Chromium team, extended to support the development of Node.js native addons.

Note that node-gyp is not used to build Node.js itself.

Multiple target versions of Node.js are supported (i.e. 0.8, ..., 456, etc.), regardless of what version of Node.js is actually installed on your system (node-gyp downloads the necessary development files or headers for the target version).

gyp是为Chromium项目创建的项目生成工具,可以从平台无关的配置生成平台相关的Visual Studio、Xcode、Makefile的项目文件。这样一来我们就不需要花额外的时间处理每个平台不同的项目配置以及项目之间的依赖关系。

npm install时遇到报错:

Building: D:\mysoft\nvm-nodejs\node.exe D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= 
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   'D:\\mysoft\\nvm-nodejs\\node.exe',
gyp verb cli   'D:\\WorkSpace\\dev\\xxx\\xxx_node\\xxx-task-center-ext\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library='
gyp verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@12.22.3 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:168:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp verb `which` failed     at getNotFoundError (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:168:21) {
gyp verb `which` failed   code: 'ENOENT'
gyp verb `which` failed }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python C:\mysoft\Python\Python39\python.EXE
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: C:\mysoft\Python\Python39\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                       ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:308:12)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at maybeClose (internal/child_process.js:1022:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
gyp ERR! System Windows_NT 10.0.19042
gyp ERR! command "D:\\mysoft\\nvm-nodejs\\node.exe" "D:\\WorkSpace\\dev\\xxx\\xxx_node\\xxx-task-center-ext\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsalibsass_library="
gyp ERR! cwd D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\node-sass
gyp ERR! node -v v12.22.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

这个错误应该是npm版本的问题,我当前的nodejs版本是12.22.3,npm版本是6.14.13(网上说npm6.14.13版本之后就可以解决,这么有针对性嘛[face]emoji:010.png[/face])

然后我直接使用nvm安装16最新版16.15.0,npm版本8.5.5,问题解决!!!

另外:

如果好奇如何实现找本地环境变量的,可参考以下:

test-find-node-directory.js

test-find-python.js

node-gyp包使用-Node.js文档类资源-CSDN下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wsdhla

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值