我正在进入一个Node.js代码库,这需要我通过NPM下载一些依赖项,即jQuery。

在尝试运行npm install jquery时,我一直得到这个错误:

Your environment has been set up for using Node.js 0.8.21 (x64) and NPM

C:\Users\Matt Cashatt>npm install jquery
npm http GET https://registry.npmjs.org/jquery
npm http 304 https://registry.npmjs.org/jquery
npm http GET https://registry.npmjs.org/jsdom
npm http GET https://registry.npmjs.org/xmlhttprequest
npm http GET https://registry.npmjs.org/htmlparser/1.7.6
npm http GET https://registry.npmjs.org/location/0.0.1
npm http GET https://registry.npmjs.org/navigator
npm http GET https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/htmlparser/1.7.6
npm http 304 https://registry.npmjs.org/xmlhttprequest
npm http 304 https://registry.npmjs.org/location/0.0.1
npm http 304 https://registry.npmjs.org/navigator
npm http 304 https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/cssom
npm http GET https://registry.npmjs.org/cssstyle
npm http GET https://registry.npmjs.org/request
npm http 304 https://registry.npmjs.org/bindings

> contextify@0.1.4 install C:\Users\Matt Cashatt\node_modules\jquery\node_module
s\contextify
> node-gyp rebuild


C:\Users\Matt Cashatt\node_modules\jquery\node_modules\contextify>node "C:\Progr
am Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\b
in\node-gyp.js" rebuild
npm http 304 https://registry.npmjs.org/cssstyle
npm http 304 https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/request
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT
HON env variable.
gyp ERR! stack     at failNoPython (C:\Program Files\nodejs\node_modules\npm\nod
e_modules\node-gyp\lib\configure.js:113:14)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node
-gyp\lib\configure.js:82:11
gyp ERR! stack     at Object.oncomplete (fs.js:297:15)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modu
les\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Matt Cashatt\node_modules\jquery\node_modules\contextify
gyp ERR! node -v v0.8.21
gyp ERR! node-gyp -v v0.8.4
gyp ERR! not ok
npm ERR! error rolling back Error: ENOTEMPTY, rmdir 'C:\Users\Matt Cashatt\node_
modules\jquery\node_modules\jsdom\node_modules\request\tests'
npm ERR! error rolling back  jquery@1.8.3 { [Error: ENOTEMPTY, rmdir 'C:\Users\M
att Cashatt\node_modules\jquery\node_modules\jsdom\node_modules\request\tests']
npm ERR! error rolling back   errno: 53,
npm ERR! error rolling back   code: 'ENOTEMPTY',
npm ERR! error rolling back   path: 'C:\\Users\\Matt Cashatt\\node_modules\\jque
ry\\node_modules\\jsdom\\node_modules\\request\\tests' }
npm ERR! contextify@0.1.4 install: `node-gyp rebuild`
npm ERR! `cmd "/c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Failed at the contextify@0.1.4 install script.
npm ERR! This is most likely a problem with the contextify package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls contextify
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "jquery"
npm ERR! cwd C:\Users\Matt Cashatt
npm ERR! node -v v0.8.21
npm ERR! npm -v 1.2.11
npm ERR! code ELIFECYCLE
npm ERR! Error: ENOENT, lstat 'C:\Users\Matt Cashatt\node_modules\jquery\node_mo
dules\jsdom\node_modules\request\tests\test-pipes.js'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "jquery"
npm ERR! cwd C:\Users\Matt Cashatt
npm ERR! node -v v0.8.21
npm ERR! npm -v 1.2.11
npm ERR! path C:\Users\Matt Cashatt\node_modules\jquery\node_modules\jsdom\node_
modules\request\tests\test-pipes.js
npm ERR! fstream_path C:\Users\Matt Cashatt\node_modules\jquery\node_modules\jsd
om\node_modules\request\tests\test-pipes.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack C:\Program Files\nodejs\node_modules\npm\node_modules\fst
ream\lib\writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:297:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Users\Matt Cashatt\npm-debug.log
npm ERR! not ok code 0

C:\Users\Matt Cashatt>

看起来失败是由于缺少Python安装。好吧,我已经安装了Python,设置了变量,然后重新启动,仍然出现错误。

你知道我错过了什么吗?


当前回答

骗子犯错!配置错误 骗子犯错!堆栈错误:无法找到Python可执行文件“Python”,您可以设置PYT HON env变量。

没有必要重新安装,此异常由node-gyp脚本抛出,然后尝试重新构建。这是足够的设置环境变量,就像在我的情况下:

SET PYTHON=C:\work\_env\Python27\python.exe

其他回答

你的问题是你没有设置环境变量。

错误明确地说:

gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.

在你的评论中,你说你是这样做的:

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

这很好,但它不设置PYTHON变量,而是设置PYTHONPATH变量。


同时,仅仅使用set命令只会影响当前的cmd会话。如果你在那之后重新启动,就像你说的那样,你最终会得到一个全新的cmd会话,其中没有设置这个变量。

有几种方法可以永久地设置环境变量——最简单的方法是在XP中的系统控制面板中,当然这在Vista中是不同的,在7中也是不同的,在8中也是不同的,但是你可以谷歌。

或者,只在npm命令之前执行set,中间不重启。


你可以测试你是否做了正确的事情,通过做config脚本试图做的事情:在运行npm之前,尝试运行%PYTHON%。如果你做对了,你会得到一个Python解释器(你可以立即退出)。如果你得到一个错误,你没有做对。


这里有两个问题:

set PYTHON=%PYTHON%;D:\Python

首先,你将PYTHON设置为;D:\ PYTHON。额外的分号适用于以分号分隔的路径列表,如PATH或PYTHONPATH,但不适用于单个值,如PYTHON。同样,当您想向路径列表中添加另一个路径时,可以向现有值中添加一个新值,但不是针对单个值。你只需要设置PYTHON=D:\ PYTHON。

其次,D:\Python不是Python解释器的路径。它类似于D:\Python\Python.exe,或D:\Python\bin\Python.exe。找到正确的路径,确保它能自己工作(例如,输入D:\Python\bin\Python.exe,并确保你有一个Python解释器),然后设置变量并使用它。


So:

set PYTHON=D:\Python\bin\Python.exe

或者,如果你想让它永久,在控制面板中做相同的操作。

为什么不在这里下载python安装程序呢?当你检查路径安装时,它会为你工作

从https://www.python.org/downloads/下载最新版本 安装时,选中“添加Python 3.10到PATH”选项。重启后,一切都很完美。

设置路径如下,它将工作

> set PYTHON=D:\\ranjith\\installed\\python-3.6.4\\python.exe

> npm config set python D:\\ranjith\\installed\\python-3.6.4\\python.exe

然后建立你的项目(对我来说)

> yarn build

例如:pg_config not executable / error node-gyp

解决方案:在windows上尝试添加PATH Env -> C:\Program Files\PostgreSQL\12\bin

为我工作,现在我可以使用npm i pg-promise为例或其他依赖。