运行npm install brain.js时出现奇怪的npm错误

3
在尝试安装brain.js时,出现了奇怪的错误,我无法理解问题在哪里以及Python在哪里出现,因为这是通过npm安装库。我在Google中没有找到类似的情况(我甚至不知道如何使用Google搜索这个问题)。
G:\firststep\BR>npm i brain.js

> gl@4.3.3 install G:\firststep\BR\node_modules\gl
> prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=10.14.2 runtime=node arch=x64 libc= platform=win32)

G:\firststep\BR\node_modules\gl>if not defined npm_config_node_gyp (node "C:\Users\rafae\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\rafae\AppData\Roaming
\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! find Python
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - "python" is not in PATH or produced an error
gyp ERR! find Python checking if "python2" can be used
gyp ERR! find Python - "python2" is not in PATH or produced an error
gyp ERR! find Python checking if the py launcher can be used to find Python 2
gyp ERR! find Python - "py.exe" is not in PATH or produced an error
gyp ERR! find Python checking if Python is C:\Python27\python.exe
gyp ERR! find Python - "C:\Python27\python.exe" could not be run
gyp ERR! find Python checking if Python is C:\Python37\python.exe
gyp ERR! find Python - "C:\Python37\python.exe" could not be run
gyp ERR! find Python
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python 2.7.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "C:\Path\To\python.exe"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (C:\Users\rafae\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-python.js:303:47)
gyp ERR! stack     at PythonFinder.runChecks (C:\Users\rafae\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-python.js:132:21)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Users\rafae\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-python.js:221:16)
gyp ERR! stack     at PythonFinder.execFileCallback (C:\Users\rafae\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-python.js:267:16)
gyp ERR! stack     at exithandler (child_process.js:301:5)
gyp ERR! stack     at ChildProcess.errorhandler (child_process.js:313:5)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:238:12)
gyp ERR! stack     at onErrorNT (internal/child_process.js:407:16)
gyp ERR! stack     at process._tickCallback (internal/process/next_tick.js:63:19)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\rafae\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd G:\firststep\BR\node_modules\gl
gyp ERR! node -v v10.14.2
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open 'G:\firststep\BR\package.json'
npm WARN BR No description
npm WARN BR No repository field.
npm WARN BR No README data
npm WARN BR No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gl@4.3.3 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gl@4.3.3 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\rafae\AppData\Roaming\npm-cache\_logs\2019-08-14T18_48_29_640Z-debug.log

brain.js 的文档中没有提及此问题。一切都很简单 - 运行 npm install brain.js 就可以了。

更新于 2019年8月16日

这篇指南的第二个选项对我有帮助: https://github.com/nodejs/node-gyp#on-windows


1
你是否已经安装了Python?Python - Dan Starns
@DanStarns,我在安装brain.js后立即看到错误,于是我立刻安装了最新版本的Python(3.7.4)。 - Rafael Shepard
但是错误信息显示 gyp ERR! find Python You need to install the latest version of Python 2.7 - 可以推测 gyp 需要的是 Python 2.7 而不是 Python 3.7.4。这两个版本之间存在不兼容性。 - NickD
1
我可以指引您安装 Node Gyp,如果您使用的是 Windows 系统,请确保安装正确的 Python 版本。Node Gyp - Dan Starns
1
@DanStarns 是的!你是对的。Brain.js 与此无关。正确安装 node gyp 是必要的。 - Rafael Shepard
2个回答

1
确保已设置Python安装的路径和环境变量。此外,我在这里找到了类似的链接.. 希望对您有所帮助!

已安装Python版本2.7,但错误仍然存在。我将继续寻找您的链接。 - Rafael Shepard
请告诉我如何为Python设置路径和环境变量。 我使用的是Windows操作系统。 - Rafael Shepard
根据您的Windows版本,您可以参考这里的步骤:https://superuser.com/questions/143119/how-do-i-add-python-to-the-windows-path。另外,一旦设置完成,您可以在命令提示符中运行命令“python -V”或“python --version”来验证Python版本。 - Anjali Shyamsundar
1
谢谢,这个工具帮了我大忙:https://www.youtube.com/watch?v=Y2q_b4ugPWk - Rafael Shepard
太好了,谢谢分享! - Anjali Shyamsundar

1

不要在命令前加点号:

npm install brainjs

那是一个不同的包。 - d0n.key

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接