Node.js:npm install时出错 check python checking for Python executable “python2“ in the PATH

1、问题描述

Building: G:\nodejs\node.exe F:\Carrie\Luxsens\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   'G:\\nodejs\\node.exe',
gyp verb cli   'F:\\Carrie\\Luxsens\\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.13.0 | 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 (F:\Carrie\Luxsens\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (F:\Carrie\Luxsens\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (F:\Carrie\Luxsens\node_modules\which\which.js:80:29)
gyp verb `which` failed     at F:\Carrie\Luxsens\node_modules\which\which.js:89:16
gyp verb `which` failed     at F:\Carrie\Luxsens\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at F:\Carrie\Luxsens\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:158:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp verb `which` failed     at getNotFoundError (F:\Carrie\Luxsens\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (F:\Carrie\Luxsens\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (F:\Carrie\Luxsens\node_modules\which\which.js:80:29)
gyp verb `which` failed     at F:\Carrie\Luxsens\node_modules\which\which.js:89:16
gyp verb `which` failed     at F:\Carrie\Luxsens\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at F:\Carrie\Luxsens\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:158:21) {
gyp verb `which` failed   stack: 'Error: not found: python2\n' +
gyp verb `which` failed     '    at getNotFoundError (F:\\Carrie\\Luxsens\\node_modules\\which\\which.js:13:12)\n' +
gyp verb `which` failed     '    at F (F:\\Carrie\\Luxsens\\node_modules\\which\\which.js:68:19)\n' +
gyp verb `which` failed     '    at E (F:\\Carrie\\Luxsens\\node_modules\\which\\which.js:80:29)\n' +
gyp verb `which` failed     '    at F:\\Carrie\\Luxsens\\node_modules\\which\\which.js:89:16\n' +
gyp verb `which` failed     '    at F:\\Carrie\\Luxsens\\node_modules\\isexe\\index.js:42:5\n' +
gyp verb `which` failed     '    at F:\\Carrie\\Luxsens\\node_modules\\isexe\\windows.js:36:5\n' +
gyp verb `which` failed     '    at FSReqCallback.oncomplete (fs.js:158: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 G:\Python\Python37-32\python.EXE
gyp ERR! configure error
gyp ERR! stack Error: Command failed: G:\Python\Python37-32\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:295:12)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "G:\\nodejs\\node.exe" "F:\\Carrie\\Luxsens\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsas
s_library="
gyp ERR! cwd F:\Carrie\Luxsens\node_modules\node-sass
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.11.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.11.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2019-11-18T07_33_10_767Z-debug.log

Process finished with exit code 1

2、解决

  1. 删除您的node_modules文件夹。
  2. npm install --global windows-build-tools --save在命令提示符下运行
  3. 使用以下命令安装node-sass :(npm install node-sass@4.12.0 --save或最新版本)
    这应该可以解决错误并给您返回gyp info ok消息!
  4. 如果遇到Node Sass could not find a binding for your current environment,请运行以下命令来解决该问题:npm rebuild node-sass
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 这个错误是由于在安装某些 npm,需要使用 Python 解释器来编译一些本地模块,但是无法找到可用的 Python 解释器。具体来说,它在尝试执行命令 "gyp verb check python" 发生错误,该命令用于检查 Python 解释器是否可用。 为了解决这个问题,你可以尝试以下几种方法: 1. 安装 Python 解释器。你可以从 Python 官方网站(https://www.python.org/downloads/)下载并安装 Python。 2. 将 Python 加入系统环境变量。在 Windows 操作系统中,你可以将 Python 的安装路径添加到 PATH 环境变量中。在 macOS 或 Linux 操作系统中,你可以将 Python 的可执行文件路径添加到 PATH 环境变量中。 3. 使用 nvm 切换到其他版本的 Node.js。有,此错误可能是由于 Node.js 版本与所需的 Python 版本不兼容造成的。你可以使用 nvm(Node Version Manager)来切换到另一个 Node.js 版本,以查看是否解决了问题。 希望这些方法能够帮助你解决问题。如果还有问题,请随向我提问。 ### 回答2: 这个错误是因为你在使用npm安装某个依赖包的候,该包需要依赖node-gyp模块进行编译,而node-gyp则需要依赖Python2.x来实现编译过程。因此,npm会检查你的电脑环境中是否已经安装了Python,并且会查找Python可执行文件路径中是否存在名为“python2”的文件。 如果你的电脑中没有安装Python或者没有设置Python的可执行文件路径,就会报出这个错误。因此,解决这个问题的方法就是安装Python2.x并将其可执行文件所在路径添加到环境变量中。 首先,你可以在Python官网(https://www.python.org/)下载Python2.x的安装包,并进行安装。安装过程中需要注意勾选“Add Python to PATH”选项,这样Python的可执行文件路径就会被添加到环境变量中。 安装完成后,你需要重新启动终端或者在终端中重新加载环境变量,才能使路径生效。之后,你再次使用npm安装需要node-gyp编译的依赖包,就不会再出现这个错误了。 ### 回答3: 这里的npm err! gyp verb check python checking for python executable "python2" in the path是指在使用npm安装或构建某些包,出现了python执行文件的检测问题。该问题通常是由于缺少Python环境引起的。 npm是一个JavaScript软件包管理器,但是,一些组件可能需要在构建过程中使用Python。要解决这个问题,需要安装Python环境,并确保python2可执行文件在系统环境变量的路径中。 在Windows系统中,安装Python是很简单的。您可以从Python官方网站下载适合您的操作系统的Python版本安装程序,运行安装程序并按照指示完成安装。 在Linux和macOS系统中,默认情况下已经安装了Python。您可以通过在命令行终端中键入“python --version”命令来检查Python的版本。如果Python未安装或版本过旧,则可以通过软件包管理器或从Python官方网站下载可执行文件进行安装。 当Python环境安装完成后,需要确保python2可执行文件已添加到系统环境变量中。在Windows系统中,您可以进入“控制面板”>“系统和安全”>“系统”>“高级系统设置”>“环境变量”,然后找到系统变量“Path”,添加Python所在路径即可。在Linux和macOS系统中,可以将Python路径添加到.bashrc文件中。 总之,通过安装Python环境并将python2可执行文件添加到系统环境变量中,就可以解决npm err! gyp verb check python checking for python executable "python2" in the path的问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

碰碰qaq

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

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

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

打赏作者

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

抵扣说明:

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

余额充值