我在使用 NPM 安装 xml2json 时遇到一些问题。
我的开发环境是这样的。
操作系统:Windows 10 专业版 64 位 IDE:Visual Studio 代码 Node 版本:8.10.0
现在我做 Node 项目。但我无法安装 xml2json。在 npmjs.com
可以用这个命令安装
$ npm install xml2json
但是命令说无法安装。错误信息是这样的。
C:\Users\super\Downloads\project\data\myapp>npm install xml2json
> node-expat@2.3.16 install C:\Users\super\Downloads\project\data\myapp\node_modules\node-expat
> node-gyp rebuild
C:\Users\super\Downloads\project\data\myapp\node_modules\node-expat>if not defined npm_config_node_gyp (node "C:\Users\super\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Users\super\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "C:\Users\super\AppData\Local\Programs\Python\Python37-32\python.EXE", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (C:\Users\super\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:483:19)
gyp ERR! stack at PythonFinder.<anonymous> (C:\Users\super\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:508:16)npm\node_modules\node-gyp\lib\configure.js:508:16) fs\polyfills.js:284:29
gyp ERR! stack at C:\Users\super\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\super\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"gyp ERR! cwd C:\Users\super\Downloads\project\data\myapp\node_modules\node-expat
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-expat@2.3.16 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-expat@2.3.16 install 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\super\AppData\Roaming\npm-cache\_logs\2018-07-31T15_33_12_196Z-debug.log
我已经安装了 python 并将其添加到路径中,但它仍然无法工作。我厌倦了用错误消息解决这个问题,但没有什么可以给我解决方案。
我已经尝试过node-gyp重建和其他方法。
最佳答案
如果其他人也遇到过这个问题,这可能会有所帮助,
- (可选)安装 Python Download From Here
在 Windows 终端中以管理员身份运行以下命令
npm install --global --product windows-build-tools
(这将安装 Windows 构建工具并安装 Python 2.7)
使用以下命令以管理员身份全局安装 node-gyp:
npm install node-gyp
就是这样!安装完成后,关闭并重新运行(通常)终端窗口,然后再次安装有问题的软件包,这应该会成功运行。
您可以查看this原创文章,如果你愿意的话。
关于node.js - xml2json 安装错误找不到 Python 可执行文件,您可以设置 PYTHON 环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51617241/