tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.26k stars 1.92k forks source link

Unable to import tfjs-node-gpu possibly due to binding.gyp not found #8323

Open batman4444 opened 3 days ago

batman4444 commented 3 days ago

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 node-gyp@10.1.0
gyp info using node@22.3.0 | 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

gaikwadrahul8 commented 3 days ago

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

  1. If you don't want to rebuild everything from scratch then please try to copy tensorflow.dll in this location node_modules/\@tensorflow/tfjs-node/lib/napi-v8/ (in napi-v8 folder) you can try below command to copy tensorflow.dll into napi-v8 folder.

cp node_modules/\@tensorflow/tfjs-node/deps/lib/tensorflow.dll node_modules/\@tensorflow/tfjs-node/lib/napi-v8/

  1. 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.

batman4444 commented 1 hour ago

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?