使用 npm 安装时找不到 python node-gyp rebuild 的可执行文件

Can't find python executable with node-gyp rebuild when installing with npm

您好,当我尝试安装先决条件以使用 sass 进行编译时出现以下错误:

$ npm install

> iltorb@1.0.13 install c:\gitrepo\PORT_BDL_BOOTSTRAP\node_modules\iltorb
> node-gyp rebuild

c:\gitrepo\PORT_BDL_BOOTSTRAP\node_modules\iltorb>if not defined npm_config_node_gyp (node "C:\Users\CTH\Desktop\bazar\nodejs\node\node_modules\npm\bin\node-gyp-bin\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )
  else (node "" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at failNoPython (C:\Users\CTH\Desktop\bazar\nodejs\node\node_modules\npm\node_modules\node-gyp\lib\configure.js:449:14)
gyp ERR! stack     at C:\Users\CTH\Desktop\bazar\nodejs\node\node_modules\npm\node_modules\node-gyp\lib\configure.js:404:11
gyp ERR! stack     at C:\Users\CTH\Desktop\bazar\nodejs\node\node_modules\npm\node_modules\graceful-fs\polyfills.js:264:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:82:15)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "c:\Users\CTH\Desktop\bazar\nodejs\node\node.exe" "C:\Users\CTH\Desktop\bazar\nodejs\node\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd c:\gitrepo\PORT_BDL_BOOTSTRAP\node_modules\iltorb
gyp ERR! node -v v5.6.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
bootstrap@4.0.0-alpha.5 c:\gitrepo\PORT_BDL_BOOTSTRAP
`-- grunt-contrib-compress@1.4.1
  `-- lodash@4.17.4

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.0.17: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: iltorb@1.0.13 (node_modules\iltorb):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: iltorb@1.0.13 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

我已经设置了 PYTHON 和 PYTHONPATH 变量,这并没有改变任何东西。该问题与 node-gyp 重建有关,该重建可能由于我的 python 可执行文件而无法正常工作。我为 windows 使用了 python 便携式版本,这可能与此有关吗?

我也试过这个没有成功:

npm config set python C:\Users\CTH\Desktop\bazar\python\App\python.exe

所以在搜索了一段时间后我想我找到了解决方案:我的 python 版本是 3.2.7 但似乎 node-gyp 只接受低于 3 的版本所以我'我发现 python 版本 2.7.6.1 的便携版本似乎可以解决我的问题。

要编译我必须使用此命令重建,因为代理似乎未通过:

node-gyp 重建 --proxy=http://proxy:8080

看起来这个问题从 v1.4.0 开始,并在 v1.4.1 中通过将 iltorb 设为 "optional dependency" 迅速得到缓解。因此,对于 v1.4.1,npm 安装会尝试编译,但即使它失败了,它也会继续进行,忽略可选的依赖项。

这个最新的行为稍微好一些,但仍然很烦人 - 速度慢并且在日志中发出太多噪音。

可以说 npm install --no-optional,这样就可以了,但这将适用于 所有 包,而不仅仅是这个包!而且您必须记住使用此选项:-) 这里有一个相关的 npm 问题:https://github.com/npm/npm/issues/14185

目前我只坚持 1。3.x: "grunt-contrib-compress": "~1.3.0",