tfjs
tfjs copied to clipboard
Unable to import tfjs-node-gpu possibly due to binding.gyp not found
I am trying to troubleshoot the following error while importing tfjs-node-gpu Everything was working with v4.17, however after moving the project folder and reinstalling all npm modules I get the following error
node:internal/modules/cjs/loader:1570
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: The specified module could not be found.
\\?\C:\GoogleDrive\Current projects\paper_table\paper_table_0.215\node_modules\@tensorflow\tfjs-node-gpu\lib\napi-v8\tfjs_binding.node
Following this guide here: https://github.com/tensorflow/tfjs/blob/master/tfjs-node/WINDOWS_TROUBLESHOOTING.md I get the following output from "node-gyp configure --verbose"
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli 'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli 'C:\\Users\\jarre\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli 'configure',
gyp verb cli '--verbose'
gyp verb cli ]
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp verb find Python Python is not set from command line or npm configuration
gyp verb find Python Python is not set from environment variable PYTHON
gyp verb find Python checking if the py launcher can be used to find Python 3
gyp verb find Python - executing "py.exe" to get Python 3 executable path
gyp verb find Python - executable path is "C:\Python312\python.exe"
gyp verb find Python - executing "C:\Python312\python.exe" to get version
gyp verb find Python - version is "3.12.4"
gyp info find Python using Python version 3.12.4 found at "C:\Python312\python.exe"
gyp verb get node dir no --target version specified, falling back to host node version: 22.3.0
gyp verb install input version string "22.3.0"
gyp verb install installing version: 22.3.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 11
gyp verb needs "installVersion" 11
gyp verb install version is good
gyp verb on Windows; need to check node.lib
gyp verb get node dir target node version installed: 22.3.0
gyp verb build dir attempting to create "build" dir: C:\GoogleDrive\Current projects\paper_table\paper_table_0.215\build
gyp verb build dir "build" dir needed to be created? No
gyp verb find VS msvs_version not set from command line or npm config
gyp verb find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp verb find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details.
gyp verb find VS
gyp verb find VS Failure details: undefined
gyp verb find VS checking VS2019 (16.11.34931.43) found at:
gyp verb find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"
gyp verb find VS - found "Visual Studio C++ core features"
gyp verb find VS - found VC++ toolset: v142
gyp verb find VS - found Windows SDK: 10.0.19041.0
gyp info find VS using VS2019 (16.11.34931.43) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"
gyp info find VS run with --verbose for detailed information
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: C:\GoogleDrive\Current projects\paper_table\paper_table_0.215\build\config.gypi
gyp verb config.gypi checking for gypi file: C:\GoogleDrive\Current projects\paper_table\paper_table_0.215\config.gypi
gyp verb common.gypi checking for gypi file: C:\GoogleDrive\Current projects\paper_table\paper_table_0.215\common.gypi
gyp verb gyp gyp format was not specified; forcing "msvs"
gyp info spawn C:\Python312\python.exe
gyp info spawn args [
gyp info spawn args 'C:\\Users\\jarre\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'msvs',
gyp info spawn args '-I',
gyp info spawn args 'C:\\GoogleDrive\\Current projects\\paper_table\\paper_table_0.215\\build\\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\jarre\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\jarre\\AppData\\Local\\node-gyp\\Cache\\22.3.0\\include\\node\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=C:\\Users\\jarre\\AppData\\Local\\node-gyp\\Cache\\22.3.0',
gyp info spawn args '-Dnode_gyp_dir=C:\\Users\\jarre\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args '-Dnode_lib_file=C:\\\\Users\\\\jarre\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\22.3.0\\\\<(target_arch)\\\\node.lib',
gyp info spawn args '-Dmodule_root_dir=C:\\GoogleDrive\\Current projects\\paper_table\\paper_table_0.215',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'C:\\GoogleDrive\\Current projects\\paper_table\\paper_table_0.215\\build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp: binding.gyp not found (cwd: C:\GoogleDrive\Current projects\paper_table\paper_table_0.215) while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.<anonymous> (C:\Users\jarre\AppData\Roaming\npm\node_modules\node-gyp\lib\configure.js:297:18)
gyp ERR! stack at ChildProcess.emit (node:events:520:28)
gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:294:12)
gyp ERR! System Windows_NT 10.0.22631
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\jarre\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--verbose"
gyp ERR! cwd C:\GoogleDrive\Current projects\paper_table\paper_table_0.215
gyp ERR! node -v v22.3.0
gyp ERR! node-gyp -v v10.1.0
gyp ERR! not ok
Error seems to be binding.gyp not found (cwd: C:...) while trying to load binding.gyp
Hi, @batman4444
Thank you for bringing this issue to our attention, I see you're trying with Python version 3.12.4 and Node.js version v22.3.0 as far I know at the moment TensorFlow.js does not support Python Version 3.12.x so please try to use Python version from 3.7.x to 3.11.x and also downgrade Node.js version to either v20.15.0 or v19.9.0
- If you don't want to rebuild everything from scratch then please try to copy
tensorflow.dllin this locationnode_modules/\@tensorflow/tfjs-node/lib/napi-v8/(innapi-v8folder) you can try below command to copytensorflow.dllintonapi-v8folder.
cp node_modules/\@tensorflow/tfjs-node/deps/lib/tensorflow.dll node_modules/\@tensorflow/tfjs-node/lib/napi-v8/
- If you're looking rebuild everything from scratch then please try below workaround :
npm install
npm update
npm rebuild bcrypt --build-from-source
npm rebuild @tensorflow/tfjs-node build-addon-from-source
Please give try it with above workaround and let us know is it working as expected or not ?
Thank you for your understanding and patience.
Moving tensorflow.dll from tfjs-node-gpu/deps/lib/ to tfjs-node-gpu/lib/napi-v8/ seemed to do the trick.
Any chance you know if this is just an install error or will I run into other problems if I don't down-grade my python/node versions?
Hi, @batman4444
Good to hear that after moving the tensorflow.dll from tfjs-node-gpu/deps/lib/ to tfjs-node-gpu/lib/napi-v8/ you're able to import tfjs-node-gpu successfully and as far I know there should not be any issue further.
You can confirm by running below code snippet with @tensorflow/tfjs-node-gpu :
import * as tf from '@tensorflow/tfjs-node-gpu'
const model = tf.sequential();
model.add(tf.layers.dense({ units: 1, inputShape: [200] }));
model.compile({
loss: 'meanSquaredError',
optimizer: 'sgd',
metrics: ['MAE']
});
// Generate some random fake data for demo purposes.
const xs = tf.randomUniform([10000, 200]);
const ys = tf.randomUniform([10000, 1]);
const valXs = tf.randomUniform([1000, 200]);
const valYs = tf.randomUniform([1000, 1]);
// Start model training process.
async function train() {
await model.fit(xs, ys, {
epochs: 100,
validationData: [valXs, valYs],
// Add the tensorBoard callback here.
callbacks: tf.node.tensorBoard('/tmp/fit_logs_1')
});
}
train();
Thank you for your cooperation and patience.
Hi, @batman4444
To confirm, have you had a chance to test the provided code snippet to verify if @tensorflow/tfjs-node-gpu is functioning as intended?
If the functionality meets expectations, please feel free to close this issue.
However, if the issue persists, kindly provide an error log for further investigation on our end.
Thank you for your cooperation and patience.
Yes, manually moving across the tensorflow.dll solved the issue.
Each time I re-install tfjs-node or tfjs-node-gpu it requires that I manually move the tensorflow.dll from tfjs-node-gpu/deps/lib/ to tfjs-node-gpu/lib/napi-v8/ in order to get it working again. Is something wrong with my configuration? What am I doing wrong during the install to have this issue persist.
I am currently using Python 3.11.9 and Node v20.15.1
I can confirm that moving tensorflow.dll to the other folder does fix that error.
But that only leads to a different error:
W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
Since cudart64_110.dll is part of cuda 11 and I have cuda 12 I needed to install the runtime libraries for older cuda.
(reminder to add that to env vars path)
After that there's another error:
W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
Meaning that I also need to install the old cudnn 8 or just the single dll. Nvidia found it fitting to put this behind a survey asking details about the company details, very annoying. (also add this to env vars path)
Now it recognized my gpu, but there is still this error:
TypeError: (0 , util_1.isNullOrUndefined) is not a function
Apparently tensorflow only supports node v22 and older, so I initially downgraded node to v22, but later I added a patch for replacing util_1.isNullOrUndefined in that file and with that patch it works with newer versions of node as well..
All of this could be avoided if tensorflow.js was kept up to date.