can't use tensorflow js
Hello I search for a solution but I don't find why is not working with tfjs, thanks
$ ncc run src/index.ts
ncc: Version 0.28.6
ncc: Compiling file index.js
ncc: Using [email protected] (local user-provided)
40kB sourcemap-register.js
92kB lib/napi-v8/tfjs_binding.node
6760kB index.js
7729kB index.js.map
29520kB deps/lib/libtensorflow_framework.2.4.1.dylib
361006kB deps/lib/libtensorflow.2.4.1.dylib
397418kB [17155ms] - ncc 0.28.6
Error: dlopen(/private/var/folders/q3/8dq9l4050qbdnl_c4dv4vwph0000gn/T/773f3629bd23e026dbb965609402115c/lib/napi-v8/tfjs_binding.node, 0x0001): Library not loaded: @loader_path/../../deps/lib/libtensorflow.dylib
Referenced from: /private/var/folders/q3/8dq9l4050qbdnl_c4dv4vwph0000gn/T/773f3629bd23e026dbb965609402115c/lib/napi-v8/tfjs_binding.node
Reason: tried: '/private/var/folders/q3/8dq9l4050qbdnl_c4dv4vwph0000gn/T/773f3629bd23e026dbb965609402115c/lib/napi-v8/../../deps/lib/libtensorflow.dylib' (no such file), '/usr/local/lib/libtensorflow.dylib' (no such file), '/usr/lib/libtensorflow.dylib' (no such file)
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1154:18)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:816:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.1833 (/private/var/folders/q3/8dq9l4050qbdnl_c4dv4vwph0000gn/T/webpack:/ia-test/node_modules/@tensorflow/tfjs-node/lib/napi-v8/tfjs_binding.node:1:1)
at __nccwpck_require__ (/private/var/folders/q3/8dq9l4050qbdnl_c4dv4vwph0000gn/T/webpack:/ia-test/webpack/bootstrap:21:1)
at Object.348 (/private/var/folders/q3/8dq9l4050qbdnl_c4dv4vwph0000gn/T/webpack:/ia-test/node_modules/@tensorflow/tfjs-node/dist/index.js:60:1)
at __nccwpck_require__ (/private/var/folders/q3/8dq9l4050qbdnl_c4dv4vwph0000gn/T/webpack:/ia-test/webpack/bootstrap:21:1)
at /private/var/folders/q3/8dq9l4050qbdnl_c4dv4vwph0000gn/T/773f3629bd23e026dbb965609402115c/index.js:171760:12
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I am running into the same issue.
@yovanoc are you running this on an M1 mac by chance? Not sure if it's related -just spitballing.
No i9
@yovanoc Do you have python 3.x or 2.x installed on your system?
After a bit of digging I found out things may not build/install properly when using 3.x. (which I am using)
I will try rebuilding with python 2.7 and report back at some point
Ok, I managed to fix this issue on my machine. For reference, I am using an M1 mac, but I was getting the same error as @yovanoc so I'm thinking it may work for i9 too.
Here's what I did:
-
Downgraded to python 2.7. I didn't want to remove my existing 3.x or change my global config, so I ended up installing
pyenvand runningpyenv install 2.7.18and then usedpyenv local 2.7.18in my project directory. -
My build system is using
webpack, so I ran into some errors as it tried to build the tensorflow externals. I had to add the following to my main webpack config:
// webpack.main.config.js
const nodeExternals = require('webpack-node-externals');
// ...
module.exports = {
entry: "./src/index.js",
// ...
externals: [nodeExternals()],
};
Since I am using a monorepo I had to add the local namespace to the allow list:
nodeExternals({
allowlist: [/^@example/]
}),
Reference: https://github.com/tensorflow/tfjs/tree/master/tfjs-node#windows--mac-os-x-requires-python-27