gyp verb check python checking for Python executable “python2“ in the PATH

gyp verb check python checking for Python executable "python2" in the PATH

  • 背景
    • 错误信息
    • 错误分析
  • 解决方案
    • 使用nvm切换node版本
    • 最终成果

背景

适用npm i安装环境时出现错误
根据错误信息,应该是node版本问题导致的,但单独安装[email protected]时也出现同样错误。

错误信息

5397 error gyp verb check python checking for Python executable "C:\Python27\python.exe" in the PATH
5397 error gyp info it worked if it ends with ok
5397 error gyp verb cli [
5397 error gyp verb cli   'C:\\Program Files\\nodejs\\node.exe',
5397 error gyp verb cli   'C:\\Users\\admin\\Documents\\WebProject\\internship\\node_modules\\node-gyp\\bin\\node-gyp.js',
5397 error gyp verb cli   'rebuild',
5397 error gyp verb cli   '--verbose',
5397 error gyp verb cli   '--libsass_ext=',
5397 error gyp verb cli   '--libsass_cflags=',
5397 error gyp verb cli   '--libsass_ldflags=',
5397 error gyp verb cli   '--libsass_library='
5397 error gyp verb cli ]
5397 error gyp info using [email protected]
5397 error gyp info using [email protected] | win32 | x64
5397 error gyp verb command rebuild []
5397 error gyp verb command clean []
5397 error gyp verb clean removing "build" directory
5397 error gyp verb command configure []
5397 error gyp verb check python checking for Python executable "C:\Python27\python.exe" in the PATH
5397 error gyp verb `which` succeeded C:\Python27\python.exe C:\Python27\python.exe
5397 error gyp verb check python version `C:\Python27\python.exe -c "import sys; print "2.7.14
5397 error gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
5397 error gyp verb get node dir no --target version specified, falling back to host node version: 16.20.0
5397 error gyp verb command install [ '16.20.0' ]
5397 error gyp verb install input version string "16.20.0"
5397 error gyp verb install installing version: 16.20.0
5397 error gyp verb install --ensure was passed, so won't reinstall if already installed
5397 error gyp verb install version not already installed, continuing with install 16.20.0
5397 error gyp verb ensuring nodedir is created C:\Users\admin\.node-gyp\16.20.0
5397 error gyp verb created nodedir C:\Users\admin\.node-gyp

错误分析

有些blog说到这种错误要安装python,或者把给node设置python的引用,也许有用,但我认为前端不是这么不方便的东西,正常都是适用包管理器就能配置好环境,基本上环境配置90%的错误都是node版本的问题。
从错误信息来看,是在使用 node 16.20 后出现的错误,基本可以考虑node版本问题

解决方案

更换node版本即可,一般旧项目使用旧node,新项目使用新node。
当前时间2023-06-03,node 版本最新稳定版是18.16。
node.js
我们常用的版本是16、10。一般切换都是在这两者切换。

使用nvm切换node版本

nvm Win下载地址

一路next安装即可。

安装完成后,使用命令安装node16 或者 node10.

nvm install 16
...
nvm use 16
nvm install 10
...
nvm use 10

正常的样子

C:\Users\admin>nvm install 10
Downloading node.js version 10.24.1 (64-bit)...
Complete
Creating C:\Users\admin\AppData\Roaming\nvm\temp

Downloading npm version 6.14.12... Complete
Installing npm v6.14.12...

Installation complete. If you want to use this version, type

nvm use 10.24.1

C:\Users\admin>nvm use 10
Now using node v10.24.1 (64-bit)

最终成果

完美解决

npm i
...
added 1854 packages from 1145 contributors in 114.747s

17 packages are looking for funding
  run `npm fund` for details

你可能感兴趣的:(node.js,npm,python)