Initialization of backend tensorflow failed Error: Could not locate the bindings file

Initialization of backend tensorflow failed Error: Could not locate the bindings file

我在 ubuntu 盒子上尝试使用 tensorflow 时收到此错误。这是新文件夹中的全新 npm 安装。我已经尝试了其他帖子的建议,但仍然无法理解。有什么我想念的吗?

Initialization of backend tensorflow failed Error: Could not locate the bindings file. Tried: → /var/nodejs/tensor/node_modules/@tensorflow/tfjs-node/build/tfjs_binding.node, ... etc

节点:v10.12.0

npm: 6.7.0

package.json

{
  "name": "tensor",
  "scripts": {
    "start": "node algo.js"
  },
  "dependencies": {
    "@tensorflow/tfjs-node": "*"
  }
}

algo.js

const tf = require('@tensorflow/tfjs-node');

以下步骤之一可能有助于解决您的问题:

  • 干净安装您的依赖项
    • 删除 node_modules 文件夹
    • 重新运行npm install
  • (重新)安装 node-gyp:
    • sudo npm install -g node-gyp
  • 通过 sudo 安装依赖项
    • sudo npm install
    • 如果此步骤有效,很可能是您的目录结构存在权限问题。您可能想查看 this question 如何解决该问题。