7

我无法安装'@tensorflow/tfjs-node'

我使用 'npm install @tensorflow/tfjs-node' 安装它,但安装失败。我尝试在有和没有 root 权限的情况下全局安装“node-pre-gyp”,但没有成功。我在节点 v12.9.0 上运行。


> fsevents@1.2.9 install /Users/username/Documents/Development/AI/Tensorflow/node_modules/fsevents
> node install

node-pre-gyp WARN Using needle for node-pre-gyp https download 
[fsevents] Success: "/Users/username/Documents/Development/AI/Tensorflow/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64/fse.node" is installed via remote

> @tensorflow/tfjs-node@1.2.9 install /Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node
> node scripts/install.js

CPU-darwin-1.2.9.tar.gz
* Downloading libtensorflow
[==============================] 10422374/bps 100% 0.0s
* Building TensorFlow Node.js bindings
node-pre-gyp install failed with error: Error: Command failed: node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using needle for node-pre-gyp https download 
node-pre-gyp WARN Tried to download(404): https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v4/1.2.9/CPU-darwin-1.2.9.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for @tensorflow/tfjs-node@1.2.9 and node@12.9.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp) 
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:344:16)
gyp ERR! stack     at ChildProcess.emit (events.js:209:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.0.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node/lib/napi-v4/tfjs_binding.node" "--module_name=tfjs_binding" "--module_path=/Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node/lib/napi-v4" "--napi_version=4" "--node_abi_napi=napi" "--napi_build_version=4" "--node_napi_label=napi-v4"
gyp ERR! cwd /Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node
gyp ERR! node -v v12.9.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node/lib/napi-v4/tfjs_binding.node --module_name=tfjs_binding --module_path=/Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node/lib/napi-v4 --napi_version=4 --node_abi_napi=napi --napi_build_version=4 --node_napi_label=napi-v4' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/username/Documents/Development/AI/Tensorflow/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:209:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
node-pre-gyp ERR! System Darwin 19.0.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/username/Documents/Development/AI/Tensorflow/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node
node-pre-gyp ERR! node -v v12.9.0
node-pre-gyp ERR! node-pre-gyp -v v0.13.0
node-pre-gyp ERR! not ok 


> nodemon@1.19.2 postinstall /Users/username/Documents/Development/AI/Tensorflow/node_modules/nodemon
> node bin/postinstall || exit 0

npm WARN tensorflow@1.0.0 No description
npm WARN tensorflow@1.0.0 No repository field.

added 362 packages from 202 contributors and audited 2419 packages in 11.642s
found 0 vulnerabilities

node-pre-gyp 安装失败,“CPU-darwin-1.2.9.tar.gz”似乎不再存在,所以我收到 404 错误。

如果这个问题可能与这个问题有些重复,那么这个问题也是: Cannot import @tensorflow/tfjs-node in nodejs

编辑:试图降级到@tensorflow/tfjs-node@1.2.8,但错误仍然存​​在:

CPU-darwin-1.2.8.tar.gz
* Downloading libtensorflow
[==============================] 10642013/bps 100% 0.0s
* Building TensorFlow Node.js bindings
node-pre-gyp install failed with error: Error: Command failed: node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using needle for node-pre-gyp https download 
node-pre-gyp WARN Tried to download(404): https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v4/1.2.8/tfjs_binding-v1.2.8-node-v72-darwin-x64.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for @tensorflow/tfjs-node@1.2.8 and node@12.9.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp) 
4

5 回答 5

3

node-pre-gyp是一个不错的工具,因为它可以为您下载预编译的二进制文件,这可以节省大量时间。问题是仍然必须为您的确切版本的 nodejs 构建二进制文件。

在您的情况下,似乎没有可用(以下行在您发布的日志文件中)。

node-pre-gyp WARN Tried to download(404): https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v4/1.2.9/CPU-darwin-1.2.9.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for @tensorflow/tfjs-node@1.2.9 and node@12.9.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp) 

如果我们查看它尝试下载的 url,但是似乎有一个可用于1.2.8版本的文件(您可以在https://storage.googleapis.com/tf-builds/获得可用文件的列表)。

因此,要么将 @tensorflow/tfjs-node 降级到 1.2.8 并尝试,要么查看node-gyp 的说明以实际让它在你的机器上构建东西(这可能是长期最好的事情)。

于 2019-09-07T16:15:08.200 回答
1

我用这个命令解决了同样的问题

npm install --production windows-build-tools

于 2019-09-15T19:43:43.560 回答
0

安装 1.5.2 时,我在 MacOS 10.15 上遇到了同样的问题。

CPU-darwin-1.5.2.tar.gz
* Downloading libtensorflow
[==============================] 15666967/bps 100% 0.0s
* Building TensorFlow Node.js bindings
node-pre-gyp install failed with error: Error: Command failed: node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v5/1.5.2/CPU-darwin-1.5.2.tar.gz
node-pre-gyp WARN Pre-built binaries not found for @tensorflow/tfjs-node@1.5.2 and node@12.15.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp)

https://www.npmjs.com/package/@tensorflow/tfjs-node#windows--mac-os-x-requires-python-27

尝试安装时必须使用 python 2.7。如果不是,您将收到与您发布的类似错误,我在 python3 venv 中,因此收到此错误;回退到 2.7 解决了这个问题。

于 2020-02-17T20:46:41.593 回答
0

尝试使用或您最喜欢的节点版本管理器稍微调整您的节点版本nvm,以确保您的napi版本与谷歌预编译的版本匹配。

我在我的服务器上使用 node v12.16.0 的 node-pre-gyp 遇到了问题(我的 windows 机器上的 node v12.21.0 工作得很好!)。我花了几个小时调试认为轻微的版本差异不会是问题,但事实证明 12.16.0 和 12.21.0 使用不同的napi版本,Google 只为特定的 napi 版本预编译 tfjs。

node这是哪个版本使用哪个版本的表格napihttps ://nodejs.org/api/n-api.html#n_api_node_api_version_matrix

以下是可用的预编译版本列表:https ://storage.googleapis.com/tf-builds/

解决方法:选择一个node使用napi您可以在 Google 的预编译版本中找到的版本。就我而言,我发现我需要pre-built-binary/napi-v7/3.9.0/CPU-linux-3.9.0.tar.gz(从错误消息中) for @tensorflow/tfjs-node@3.9.0,所以我检查了节点 API 表以发现这意味着我想要 node version v12.19.0

对于 OP 的问题,它正在尝试抓取pre-built-binary/napi-v4/1.2.9/CPU-darwin-1.2.9.tar.gz,它现在似乎已经建成(截至 2021 年底)。

于 2021-09-13T14:00:23.917 回答
0

使用 node-v12.18.3 解决此错误

您可以使用此链接下载此版本

https://nodejs.org/en/blog/release/v12.18.3/
于 2020-11-10T17:12:07.203 回答