tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.

Home Page:https://js.tensorflow.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@tensorflow/tfjs-node error on windows

fedsun opened this issue · comments

i cant install tfjs on windows 10.
But I keep getting some errors . Can you please help?
python version: 3.9.17
Visual studio: 2017
node.js: 19.9.0
npm: 9.6.3

npm install --save-exact @tensorflow/tfjs-node@3.18.0

this is what I get
`PS D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4> npm install --save-exact @tensorflow/tfjs-node@3.18.0
npm WARN cleanup Failed to remove some directories [
npm WARN cleanup [
npm WARN cleanup 'D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4\node_modules\@tensorflow\tfjs-backend-webgl',
npm WARN cleanup [Error: EPERM: operation not permitted, rmdir 'D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4\node_modules@tensorflow\tfjs-backend-webgl\dist\kernels'] {
npm WARN cleanup errno: -4048,
npm WARN cleanup code: 'EPERM',
npm WARN cleanup syscall: 'rmdir',
npm WARN cleanup path: 'D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4\node_modules\@tensorflow\tfjs-backend-webgl\dist\kernels'
npm WARN cleanup }
npm WARN cleanup ],
npm WARN cleanup [
npm WARN cleanup 'D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4\node_modules\@tensorflow\tfjs-node',
npm WARN cleanup [Error: EPERM: operation not permitted, rmdir 'D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4\node_modules@tensorflow\tfjs-node\node_modules@mapbox'] {
npm WARN cleanup errno: -4048,
npm WARN cleanup code: 'EPERM',
npm WARN cleanup syscall: 'rmdir',
npm WARN cleanup path: 'D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4\node_modules\@tensorflow\tfjs-node\node_modules\@mapbox'
npm WARN cleanup }
npm WARN cleanup ],
npm WARN cleanup [
npm WARN cleanup 'D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4\node_modules\@tensorflow',
npm WARN cleanup [Error: EPERM: operation not permitted, rmdir 'D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4\node_modules@tensorflow\tfjs-node\node_modules@mapbox'] {
npm WARN cleanup errno: -4048,
npm WARN cleanup code: 'EPERM',
npm WARN cleanup syscall: 'rmdir',
npm WARN cleanup path: 'D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4\node_modules\@tensorflow\tfjs-node\node_modules\@mapbox'
npm WARN cleanup }
npm WARN cleanup ]
npm WARN cleanup ]
npm ERR! code 1
npm ERR! path D:\work\task\3.tensorflow\tensorflow\tensorflow-demo4\node_modules@tensorflow\tfjs-node
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/install.js
npm ERR! CPU-windows-3.18.0.zip
npm ERR! https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-2.7.0.zip
npm ERR! * Downloading libtensorflow
npm ERR! node:events:491
npm ERR! throw er; // Unhandled 'error' event
npm ERR! ^
npm ERR!
npm ERR! Error: read ECONNRESET
npm ERR! at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
npm ERR! Emitted 'error' event on ClientRequest instance at:
npm ERR! at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR! at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
npm ERR! errno: -4077,
npm ERR! code: 'ECONNRESET',
npm ERR! syscall: 'read'
npm ERR! }
npm ERR!
npm ERR! Node.js v19.9.0

npm ERR! A complete log of this run can be found in: C:\Users\Administrator\AppData\Local\npm-cache_logs\2024-03-12T17_44_39_484Z-debug-0.log`

HI @fedsun ,

It seems like npm is having trouble removing files during an operation for new version upgrade. This might be causing the EPERM error. Additionally, there could be a network issue preventing downloads, indicated by the ECONNRESET error.

For First Error:
Manually delete the node_modules folder and package-lock.json file and Run the command npm cache clean --force
For ECONNRESET error: Check if you're behind a firewall that's preventing package downloads.

Also, there's a known compatibility issue with the latest versions of Node.js. See the following comment. Let me know if it helps. Thank You!!

Thank you for your advice. I have checked my firewall and found no problem. It may not be my computer firewall blocking it.

Hi, @fedsun

I have tried to replicate the same issue from my end with Node version 19.9.0 with Python version 3.9.10 and I'm able to install latest version of @tensorflow/tfjs-node for your reference I have added screenshot so please follow the same commands with same sequence which I used below and before that please make sure you've followed the same instructions mentioned in my comment before installing the @tensorflow/tfjs-node in that I suggested to use either @tensorflow/tfjs-node@3.18.0 or @tensorflow/tfjs-node@3.10.0 but I tried latest version of @tensorflow/tfjs-node@4.17.0 from my end and it's working as expected and make sure that you're using the command prompt with administrator permission because I see in your error log there is some operation not permitted due to administrator permission was not given

Please give it try with above workaround and see is it resolving your issue or not ? if issue still persists please help us with error log after running this command node-gyp configure to investigate your issue further from our end.

Thank you for your understanding and patience.

PS C:\Users\gaikwadrahul\Desktop\test-8202> node -v
v19.9.0
PS C:\Users\gaikwadrahul\Desktop\test-8202> npm -v
9.6.3
PS C:\Users\gaikwadrahul\Desktop\test-8202> python
Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
PS C:\Users\gaikwadrahul\Desktop\test-8202> npm init -y
PS C:\Users\gaikwadrahul\Desktop\test-8202> npm install -g node-gyp

changed 101 packages in 12s
PS C:\Users\gaikwadrahul\Desktop\test-8202> npm install @tensorflow/tfjs-node

up to date, audited 122 packages in 1s

9 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
PS C:\Users\gaikwadrahul\Desktop\test-8202> node .\index.js
2024-03-18 12:04:54.474812: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Epoch 1 / 10
eta=0.0 ==================================================================================>
3073ms 307us/step - MAE=0.327 loss=0.166 val_MAE=0.303 val_loss=0.138
Epoch 2 / 10
eta=0.0 ==================================================================================>
2017ms 202us/step - MAE=0.277 loss=0.110 val_MAE=0.259 val_loss=0.0947
Epoch 3 / 10
eta=0.0 ==================================================================================>
2126ms 213us/step - MAE=0.261 loss=0.0944 val_MAE=0.252 val_loss=0.0883
Epoch 4 / 10
eta=0.0 ==================================================================================>
2123ms 212us/step - MAE=0.253 loss=0.0875 val_MAE=0.247 val_loss=0.0837
Epoch 5 / 10
eta=0.0 ==================================================================================>
1960ms 196us/step - MAE=0.250 loss=0.0851 val_MAE=0.243 val_loss=0.0803
Epoch 6 / 10
eta=0.0 ==================================================================================>
2440ms 244us/step - MAE=0.250 loss=0.0847 val_MAE=0.244 val_loss=0.0814
Epoch 7 / 10
eta=0.0 ==================================================================================>
1754ms 175us/step - MAE=0.249 loss=0.0843 val_MAE=0.296 val_loss=0.131
Epoch 8 / 10
eta=0.0 ==================================================================================>
2062ms 206us/step - MAE=0.248 loss=0.0838 val_MAE=0.242 val_loss=0.0793
Epoch 9 / 10
eta=0.0 ==================================================================================>
1721ms 172us/step - MAE=0.249 loss=0.0841 val_MAE=0.242 val_loss=0.0792
Epoch 10 / 10
eta=0.0 ==================================================================================>
1703ms 170us/step - MAE=0.248 loss=0.0837 val_MAE=0.246 val_loss=0.0825
PS C:\Users\gaikwadrahul\Desktop\test-8202> 

Here is the operation I reproduced following your advice. I can ensure that I opened PowerShell with administrative privileges, and tensorflow-demo5 is an empty folder.

PS D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5> node -v
v19.9.0
PS D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5> npm -v
9.6.3
PS D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5> python
Python 3.9.17 (main, Jul 21 2023, 23:47:36) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
PS D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5> npm init -y
Wrote to D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5\package.json:

{
  "name": "tensorflow-demo5",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
PS D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5> npm install -g node-gyp

changed 101 packages in 28s
PS D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5> npm install @tensorflow/tfjs-node
npm WARN cleanup Failed to remove some directories [
npm WARN cleanup   [
npm WARN cleanup     'D:\\work\\task\\3-tensorflow\\tensorflow\\tensorflow-demo5\\node_modules',
npm WARN cleanup     [Error: EPERM: operation not permitted, rmdir 'D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5\node_modules\@tensorflow\tfjs-backend-cpu\dist\kernels'] {
npm WARN cleanup       errno: -4048,
npm WARN cleanup       code: 'EPERM',
npm WARN cleanup       syscall: 'rmdir',
npm WARN cleanup       path: 'D:\\work\\task\\3-tensorflow\\tensorflow\\tensorflow-demo5\\node_modules\\@tensorflow\\tfjs-backend-cpu\\dist\\kernels'
npm WARN cleanup     }
npm WARN cleanup   ],
npm WARN cleanup   [
npm WARN cleanup     'D:\\work\\task\\3-tensorflow\\tensorflow\\tensorflow-demo5\\node_modules\\@tensorflow',
npm WARN cleanup     [Error: EPERM: operation not permitted, rmdir 'D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5\node_modules\@tensorflow\tfjs-core\dist\public\chained_ops'] {
npm WARN cleanup       errno: -4048,
npm WARN cleanup       code: 'EPERM',
npm WARN cleanup       syscall: 'rmdir',
npm WARN cleanup       path: 'D:\\work\\task\\3-tensorflow\\tensorflow\\tensorflow-demo5\\node_modules\\@tensorflow\\tfjs-core\\dist\\public\\chained_ops'
npm WARN cleanup     }
npm WARN cleanup   ]
npm WARN cleanup ]
npm ERR! code 1
npm ERR! path D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5\node_modules\@tensorflow\tfjs-node
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/install.js
npm ERR! CPU-windows-4.17.0.zip
npm ERR! https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-2.9.1.zip
npm ERR! * Downloading libtensorflow
npm ERR! node:events:491
npm ERR!       throw er; // Unhandled 'error' event
npm ERR!       ^
npm ERR!
npm ERR! Error: read ECONNRESET
npm ERR!     at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
npm ERR! Emitted 'error' event on ClientRequest instance at:
npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:495:9)
npm ERR!     at TLSSocket.emit (node:events:513:28)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
npm ERR!   errno: -4077,
npm ERR!   code: 'ECONNRESET',
npm ERR!   syscall: 'read'
npm ERR! }
npm ERR!
npm ERR! Node.js v19.9.0

npm ERR! A complete log of this run can be found in: C:\Users\Administrator\AppData\Local\npm-cache\_logs\2024-03-20T10_10_31_196Z-debug-0.log

`PS D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5> node-gyp configure
gyp info it worked if it ends with ok
gyp info using node-gyp@10.0.1
gyp info using node@19.9.0 | win32 | x64
gyp info find Python using Python version 3.9.17 found at "D:\DeveloperTools\python-3.9.17-amd64\python.exe"

gyp info find VS using VS2017 (15.9.34601.69) found at:
gyp info find VS "D:\DeveloperTools\VisualStudio2017\VS2017-IDE"
gyp info find VS run with --verbose for detailed information
gyp info spawn D:\DeveloperTools\python-3.9.17-amd64\python.exe
gyp info spawn args [
gyp info spawn args 'D:\DeveloperTools\nvm-windows-1.1.12\nvm\v19.9.0\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 'D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5\build\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'D:\DeveloperTools\nvm-windows-1.1.12\nvm\v19.9.0\node_modules\node-gyp\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\Users\Administrator\AppData\Local\node-gyp\Cache\19.9.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\Administrator\AppData\Local\node-gyp\Cache\19.9.0',
gyp info spawn args '-Dnode_gyp_dir=D:\DeveloperTools\nvm-windows-1.1.12\nvm\v19.9.0\node_modules\node-gyp',
gyp info spawn args '-Dnode_lib_file=C:\\Users\\Administrator\\AppData\\Local\\node-gyp\\Cache\\19.9.0\\<(target_arch)\\node.lib',
gyp info spawn args '-Dmodule_root_dir=D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5',
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 'D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5\build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp: binding.gyp not found (cwd: D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5) 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. (D:\DeveloperTools\nvm-windows-1.1.12\nvm\v19.9.0\node_modules\node-gyp\lib\configure.js:271:18)
gyp ERR! stack at ChildProcess.emit (node:events:513:28)
gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:293:12)
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\node-gyp\bin\node-gyp.js" "configure"
gyp ERR! cwd D:\work\task\3-tensorflow\tensorflow\tensorflow-demo5
gyp ERR! node -v v19.9.0
gyp ERR! node-gyp -v v10.0.1
gyp ERR! not ok`

Hi, @fedsun

Thank you for sharing the complete error log to investigate your issue further, I would suggest you to please follow below steps with Node v19.9.0 and different Python versions like 3.6, 3.7, 3.8, 3.9,3.10 or 3.11, if it did not work then please try with this specific versions Node v18.16.1, Pyhton 3.9.13, node-gyp 10.0.1, npm 9.5.1 and it should work

  • Step 1-: Create new folder and move to that folder by using cd folder_name then run command npm init -y it will create empty Node.js project
  • Step 2-: npm install -g node-gyp Or sudo npm install -g node-gyp
  • Step 3-: Download the Visual Studio Build Tools and select the Desktop development C++ (keep it default settings option)
  • Step 4 -: node-gyp configure --msvs_version=2017 Or sudo node-gyp configure --msvs_version=2017 (run this command)
  • Step 5-: set npm_config_python="C:\path\to\python.exe" Or sudo set npm_config_python="C:\path\to\python.exe(Replace your python.exe path in double quotes )
  • Step 6-: go to your project directory and try to install (npm install @tensorflow/tfjs-node Or sudo npm install @tensorflow/tfjs-node)

tfjs-node requires AVX processors and tfjs-node library uses AVX instructions to improve the performance of its operations. If your CPU does not support AVX, as far I know you will not be able to use tfjs-node if I'm not wrong so to check AVX support please follow below steps

  • Right-click on the Start button and select "System Information."
  • Expand the "Processor" category in the left-hand pane.
  • Look for "Instruction Set" or "Extended Instructions" in the right-hand pane. If AVX is supported, you should see it listed there (e.g., "AVX2").

Thank you for your understanding and patience.