无法安装tensorflow js

Cannot install tensorflow js

我正在尝试安装 tensorflow 依赖项,但在终端控制台中出现错误。

我的package.json:

{
  "name": "knn-tf",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@tensorflow/tfjs-node": "^0.1.17",
    "lodash": "^4.17.11",
    "shuffle-seed": "^1.1.6"
  }
}

* Building TensorFlow Node.js bindings
/Users/mateusz/WebstormProjects/ML_JS/MLKits/knn-tf/node_modules/@tensorflow/tfjs-node/scripts/install.js:154
      throw new Error('node-gyp rebuild failed with: ' + err);
      ^

Error: node-gyp rebuild failed with: Error: Command failed: node-gyp rebuild
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.
No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.



gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.5.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/mateusz/WebstormProjects/ML_JS/MLKits/knn-tf/node_modules/@tensorflow/tfjs-node
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v5.0.7
gyp ERR! not ok 

    at /Users/mateusz/WebstormProjects/ML_JS/MLKits/knn-tf/node_modules/@tensorflow/tfjs-node/scripts/install.js:154:13
    at ChildProcess.exithandler (child_process.js:302:5)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
npm WARN knn-tf@1.0.0 No description
npm WARN knn-tf@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @tensorflow/tfjs-node@0.1.21 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @tensorflow/tfjs-node@0.1.21 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!     /Users/mateusz/.npm/_logs/2020-06-05T21_16_30_200Z-debug.log

这发生在我 运行 npm i

我曾尝试删除 node_modules 并从头开始安装它,但没有帮助。

你知道如何解决吗?

一些节点模块正在使用 node-gyp 来编译它们的代码。

你的情况是使用macos所以你需要安装macos的编译工具

您可以通过安装命令行工具来做到这一点。这可以通过执行

轻松完成
xcode-select --install

或从应用商店xcode安装

命令行工具安装完成后,重新运行npm install(会建议您删除之前的node_module目录)