即使在%PYTHON%被设置之后,Node.js(npm)也拒绝findpython
所以我试图让Node.js工作。 当然,这不像广告一样简单:)
我碰巧在我的电脑上有两个python版本,但Node.js似乎只适用于较旧的2.7版本。 出现错误时,也鼓励我将此path设置为PYTHON
环境variables:
Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
那好吧,我根据需要configurationvariables:
C:\Users\Jakub>set PYTHON=C:\MYSELF\Programs\Python2.7\python.exe C:\Users\Jakub>echo %PYTHON% C:\MYSELF\Programs\Python2.7\python.exe
你可以看到我用echo
来检查variables是否真的被设置。 不幸的是,那个npm
东西无法读取,错误再次出现。 以下是设置%PYTHON%
variables后的完整日志:
C:\Users\Jakub>npm install minecraft-protocol \ > ursa@0.8.5 install C:\Users\Jakub\node_modules\minecraft-protocol\node_modules\ursa > node-gyp rebuild | C:\Users\Jakub\node_modules\minecraft-protocol\node_modules\ursa>if not defined npm_config_node_gyp (node "C:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\no de_modules\node-gyp\bin\node-gyp.js" rebuild ) else (rebuild) gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable. gyp ERR! stack at failNoPython (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:103:14) gyp ERR! stack at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:64:11 gyp ERR! stack at FSReqWrap.oncomplete (evalmachine.<anonymous>:95:15)
我想出了最稳定的解决scheme是将python
npm内部值设置为实际的path:
npm config set python C:\Programs\Python2.7\python2.7.exe
这将跳过所有的环境variables和%PATH%
垃圾,只是启动python的地方安装。
TL; DR使用名称python2.7.exe制作您的python.exe的副本或别名
我的Python 2.7被安装为
d:\程序\ Python27 \ python.exe
我总是得到这个错误,无论我如何设置(和validation)PYTHON envvariables:
gyp ERR! 堆栈错误:找不到Python可执行文件“python2.7”,可以设置PYTHON envvariables。 gyp ERR! 在failNoPython(C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ node-gyp \ lib \ configure.js:103:14)
原因是在node-gyp的configure.js中,python可执行文件被parsing为:
var python = gyp.opts.python || process.env.PYTHON || 'python'
事实certificate,gyp.opts.python的价值“python2.7”,从而覆盖process.env.PYTHON。
我通过为名称node-gyp寻找的python.exe可执行文件创build一个别名来解决这个问题:
D:\app\Python27>mklink python2.7.exe python.exe
您需要此操作的pipe理员权限。
设置你的环境variables后重新打开你的terminal在Windows的情况下,但在Linux的情况下,无需重新启动terminal。