添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! I'm new with node-red and I wanted to install tensor flow, using this in cmd:
C:\Users\mahya\.node-red>npm install @tensorflow/tfjs-node
But I keep getting some errors . Can you please help?
My system information is a Windows 10 Home, 22H2 version.
python version: 3.10.6

this is what I get
`C:\Users\mahya.node-red>npm install @tensorflow/tfjs-node
npm ERR! code 1
npm ERR! path C:\Users\mahya.node-red\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.10.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!
npm ERR! C:\Users\mahya.node-red\node_modules\adm-zip\zipFile.js:101
npm ERR! if (!~endOffset) throw new Error(Utils.Errors.INVALID_FORMAT);
npm ERR! ^
npm ERR!
npm ERR! Error: Invalid or unsupported zip format. No END header found
npm ERR! at readMainHeader (C:\Users\mahya.node-red\node_modules\adm-zip\zipFile.js:101:32)
npm ERR! at new module.exports (C:\Users\mahya.node-red\node_modules\adm-zip\zipFile.js:19:9)
npm ERR! at new module.exports (C:\Users\mahya.node-red\node_modules\adm-zip\adm-zip.js:62:18)
npm ERR! at WriteStream. (C:\Users\mahya.node-red\node_modules@tensorflow\tfjs-node\scripts\resources.js:72:29)
npm ERR! at WriteStream.emit (node:events:514:28)
npm ERR! at emitCloseNT (node:internal/streams/destroy:132:10)
npm ERR! at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
npm ERR!
npm ERR! Node.js v18.17.1

npm ERR! A complete log of this run can be found in: C:\Users\mahya\AppData\Local\npm-cache_logs\2023-08-28T13_33_29_211Z-debug-0.log`

I've also attached the log [file. ]
2023-08-28T13_33_29_211Z-debug-0.log

Hi, @mahyasch

Thank you for bringing this issue to our attention and Please refer this official documentation for TensorFlow.js Node.js bindings Windows troubleshooting and node-gyp - Node.js native addon build tool instructions from here for Windows machine

node-gyp requires that you have installed a compatible version of Python, one of: v3.7, v3.8, v3.9, or v3.10.

Please try to use below steps :

  • npm install -g node-gyp
  • npm install --save-exact @tensorflow/[email protected]
  • Could you please try above instructions with @tensorflow/[email protected] and let us know, Is it resolving your issue or not ? If not please share error log after following above instructions ? Thank you!

    run `npm fund` for details C:\Users\mahya>npm install --save-exact @tensorflow/[email protected] npm ERR! code ENOTEMPTY npm ERR! syscall rmdir npm ERR! path C:\Users\mahya\node_modules\@tensorflow\tfjs-node\node_modules\@tensorflow\tfjs\dist npm ERR! errno -4051 npm ERR! ENOTEMPTY: directory not empty, rmdir 'C:\Users\mahya\node_modules\@tensorflow\tfjs-node\node_modules\@tensorflow\tfjs\dist' npm ERR! A complete log of this run can be found in: C:\Users\mahya\AppData\Local\npm-cache\_logs\2023-08-29T13_04_03_147Z-debug-0.log``` C:\Users\mahya>python --version Python 3.10.6

    Hi, @mahyasch

    Could you please try to use above workaround by creating new node.js project instead of existing project and see, Is it resolving your issue or not ?

    If issue still persists, let us know with error log to investigate your issue further. Thank you!

    How can I create a new node.js project?
    I just run the code in the Windows command prompt. Should I do a different thing?
    Can you please help me about what should I do step by step?
    I'm new with these stuff.
    Thank you so much.

    @mahyasch

    Please use below steps and before that you should follow this official documentation on Windows for node-gyp - Node.js native addon build tool.

    I hope it will help you to resolve your issue, if you need any further help let us know. Thank you!

  • To create one empty folder use, mkdir Folder_Name then go to that folder by using cd Folder_Name
  • To create empty node.js project use, npm init -y
  • npm install -g node-gyp
  • npm install --save-exact @tensorflow/[email protected]
  • I did that and still it is not fixed.
    I have two versions of python)10 & 11), is it the issue?

     -V:3.11 *        C:\Users\mahya\AppData\Local\Programs\Python\Python311\python.exe
     -V:3.10          C:\Python310\python.exe
     -V:ContinuumAnalytics/Anaconda39-64 C:\Users\mahya\anaconda3\python.exe
    C:\Users\mahya>set npm_config_python=C:\path\to\python.exe
    C:\Users\mahya>mkdir Folder
    C:\Users\mahya>npm init -y
    Wrote to C:\Users\mahya\package.json:
    [2023-08-29T14_25_52_415Z-debug-0.log](https://github.com/tensorflow/tfjs/files/12465642/2023-08-29T14_25_52_415Z-debug-0.log)
      "dependencies": {
        "@tensorflow/tfjs": "^4.10.0"
      "name": "mahya",
      "version": "1.0.0",
      "main": "index.js",
      "devDependencies": {},
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      "keywords": [],
      "author": "",
      "license": "ISC",
      "description": ""
    C:\Users\mahya>npm install -g node-gyp
    changed 129 packages in 11s
    17 packages are looking for funding
      run `npm fund` for details
    C:\Users\mahya>npm install --save-exact @tensorflow/[email protected]
    npm WARN deprecated [email protected]: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
    npm WARN cleanup Failed to remove some directories [
    npm WARN cleanup   [
    npm WARN cleanup     'C:\\Users\\mahya\\node_modules\\@tensorflow\\tfjs-node\\node_modules',
    npm WARN cleanup     [Error: EPERM: operation not permitted, rmdir 'C:\Users\mahya\node_modules\@tensorflow\tfjs-node\node_modules\@tensorflow\tfjs-core\dist'] {
    npm WARN cleanup       errno: -4048,
    npm WARN cleanup       code: 'EPERM',
    npm WARN cleanup       syscall: 'rmdir',
    npm WARN cleanup       path: 'C:\\Users\\mahya\\node_modules\\@tensorflow\\tfjs-node\\node_modules\\@tensorflow\\tfjs-core\\dist'
    npm WARN cleanup     }
    npm WARN cleanup   ]
    npm WARN cleanup ]
    npm ERR! code 1
    npm ERR! path C:\Users\mahya\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.1.0.zip
    npm ERR! * Downloading libtensorflow
    npm ERR!
    npm ERR! C:\Users\mahya\node_modules\adm-zip\zipFile.js:107
    npm ERR!                        throw new Error(Utils.Errors.INVALID_FORMAT);
    npm ERR!                              ^
    npm ERR!
    npm ERR! Error: Invalid or unsupported zip format. No END header found
    npm ERR!     at readMainHeader (C:\Users\mahya\node_modules\adm-zip\zipFile.js:107:10)
    npm ERR!     at new module.exports (C:\Users\mahya\node_modules\adm-zip\zipFile.js:19:3)
    npm ERR!     at new module.exports (C:\Users\mahya\node_modules\adm-zip\adm-zip.js:20:11)
    npm ERR!     at WriteStream.<anonymous> (C:\Users\mahya\node_modules\@tensorflow\tfjs-node\scripts\resources.js:69:29)
    npm ERR!     at WriteStream.emit (node:events:514:28)
    npm ERR!     at emitCloseNT (node:internal/streams/destroy:132:10)
    npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
    npm ERR!
    npm ERR! Node.js v18.17.1
    npm ERR! A complete log of this run can be found in: C:\Users\mahya\AppData\Local\npm-cache\_logs\2023-08-29T14_25_52_415Z-debug-0.log
              

    And also I've tried to install tensorflow in Jupyter notebook, but I couldn't.
    Do they relate?
    There the error was:
    ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied: 'C:\\Users\\mahya\\anaconda3\\Lib\\site-packages\\~umpy\\core\\_multiarray_tests.cp39-win_amd64.pyd' Consider using the --user option or check the permissions.

    but with !pip install --user tensorflow
    I got these warnings:
    WARNING: The script google-oauthlib-tool.exe is installed in 'C:\Users\mahya\AppData\Roaming\Python\Python39\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: The script tensorboard.exe is installed in 'C:\Users\mahya\AppData\Roaming\Python\Python39\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: The scripts estimator_ckpt_converter.exe, import_pb_to_tensorboard.exe, saved_model_cli.exe, tensorboard.exe, tf_upgrade_v2.exe, tflite_convert.exe, toco.exe and toco_from_protos.exe are installed in 'C:\Users\mahya\AppData\Roaming\Python\Python39\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

    and still:

    Input In [4], in <cell line: 1>()
    ----> 1 import tensorflow as tf
          2 a = tf.constant(5)
          3 b = tf.constant(10)
    ModuleNotFoundError: No module named 'tensorflow'```
    

    I did that and still it is not fixed. I have two versions of python)10 & 11), is it the issue?

     -V:3.11 *        C:\Users\mahya\AppData\Local\Programs\Python\Python311\python.exe
     -V:3.10          C:\Python310\python.exe
     -V:ContinuumAnalytics/Anaconda39-64 C:\Users\mahya\anaconda3\python.exe
    C:\Users\mahya>set npm_config_python=C:\path\to\python.exe
    C:\Users\mahya>mkdir Folder
    C:\Users\mahya>npm init -y
    Wrote to C:\Users\mahya\package.json:
    [2023-08-29T14_25_52_415Z-debug-0.log](https://github.com/tensorflow/tfjs/files/12465642/2023-08-29T14_25_52_415Z-debug-0.log)
      "dependencies": {
        "@tensorflow/tfjs": "^4.10.0"
      "name": "mahya",
      "version": "1.0.0",
      "main": "index.js",
      "devDependencies": {},
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      "keywords": [],
      "author": "",
      "license": "ISC",
      "description": ""
    C:\Users\mahya>npm install -g node-gyp
    changed 129 packages in 11s
    17 packages are looking for funding
      run `npm fund` for details
    C:\Users\mahya>npm install --save-exact @tensorflow/[email protected]
    npm WARN deprecated [email protected]: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
    npm WARN cleanup Failed to remove some directories [
    npm WARN cleanup   [
    npm WARN cleanup     'C:\\Users\\mahya\\node_modules\\@tensorflow\\tfjs-node\\node_modules',
    npm WARN cleanup     [Error: EPERM: operation not permitted, rmdir 'C:\Users\mahya\node_modules\@tensorflow\tfjs-node\node_modules\@tensorflow\tfjs-core\dist'] {
    npm WARN cleanup       errno: -4048,
    npm WARN cleanup       code: 'EPERM',
    npm WARN cleanup       syscall: 'rmdir',
    npm WARN cleanup       path: 'C:\\Users\\mahya\\node_modules\\@tensorflow\\tfjs-node\\node_modules\\@tensorflow\\tfjs-core\\dist'
    npm WARN cleanup     }
    npm WARN cleanup   ]
    npm WARN cleanup ]
    npm ERR! code 1
    npm ERR! path C:\Users\mahya\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.1.0.zip
    npm ERR! * Downloading libtensorflow
    npm ERR!
    npm ERR! C:\Users\mahya\node_modules\adm-zip\zipFile.js:107
    npm ERR!                        throw new Error(Utils.Errors.INVALID_FORMAT);
    npm ERR!                              ^
    npm ERR!
    npm ERR! Error: Invalid or unsupported zip format. No END header found
    npm ERR!     at readMainHeader (C:\Users\mahya\node_modules\adm-zip\zipFile.js:107:10)
    npm ERR!     at new module.exports (C:\Users\mahya\node_modules\adm-zip\zipFile.js:19:3)
    npm ERR!     at new module.exports (C:\Users\mahya\node_modules\adm-zip\adm-zip.js:20:11)
    npm ERR!     at WriteStream.<anonymous> (C:\Users\mahya\node_modules\@tensorflow\tfjs-node\scripts\resources.js:69:29)
    npm ERR!     at WriteStream.emit (node:events:514:28)
    npm ERR!     at emitCloseNT (node:internal/streams/destroy:132:10)
    npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
    npm ERR!
    npm ERR! Node.js v18.17.1
    npm ERR! A complete log of this run can be found in: C:\Users\mahya\AppData\Local\npm-cache\_logs\2023-08-29T14_25_52_415Z-debug-0.log
    

    Hi, @mahyasch
    I believe you're following this official documentation and at the moment it seems like multiple python versions causing this issue so could you please try Configuring Python Dependency on windows

    py --list-paths  # To see the installed Python versions
    set npm_config_python=C:\path\to\python.exe
    

    I see deprecated [email protected]: Please upgrade to @mapbox/node-pre-gyp in the above log,

    Run the following command to uninstall the old version of @mapbox/node-pre-gyp:
    npm uninstall node-pre-gyp --save

    Run the following command to install the latest version of @mapbox/node-pre-gyp:
    npm install @mapbox/node-pre-gyp --save

    If issue still persists, let us know with error log. Thank you!

    thanks but there are two issues, first:
    C:\Windows\system32>py --list-paths # To see the installed Python versions -V:3.11 * C:\Users\mahya\AppData\Local\Programs\Python\Python311\python.exe -V:3.10 C:\Python310\python.exe -V:ContinuumAnalytics/Anaconda39-64 C:\Users\mahya\anaconda3\python.exe

    when i run this C:\Windows\system32>set npm_config_python=C:\path\to\python.exe nothing happens. At least there is no output, I don't know if I should see any output or not.
    After I followed those two steps as you said. It was the result:

    up to date in 608ms C:\Windows\system32>npm install @mapbox/node-pre-gyp --save added 58 packages, and audited 59 packages in 5s 4 packages are looking for funding run `npm fund` for details found 0 vulnerabilities```

    Then I tried again to install tfjs-nodes using this command C:\Windows\system32>npm install @tensorflow/tfjs-node but still:
    2023-08-30T09_08_44_083Z-debug-0.log
    this is the log.

    I did but the issue is still there.
    Thank you for your guidance, I think I might find an alternative to work with deep learning in Node-Red.
    It seems this tfjs-node doesn't work with my device however I tried to fix it.

    2023-08-31T19_07_41_628Z-debug-0.log

    npm WARN cleanup Failed to remove some directories [
    npm WARN cleanup   [
    npm WARN cleanup     'C:\\Windows\\system32\\node_modules\\@tensorflow\\tfjs-node\\node_modules',
    npm WARN cleanup     [Error: EPERM: operation not permitted, rmdir 'C:\Windows\system32\node_modules\@tensorflow\tfjs-node\node_modules\@mapbox\node-pre-gyp'] {
    npm WARN cleanup       errno: -4048,
    npm WARN cleanup       code: 'EPERM',
    npm WARN cleanup       syscall: 'rmdir',
    npm WARN cleanup       path: 'C:\\Windows\\system32\\node_modules\\@tensorflow\\tfjs-node\\node_modules\\@mapbox\\node-pre-gyp'
    npm WARN cleanup     }
    npm WARN cleanup   ]
    npm WARN cleanup ]
    npm ERR! code ERR_INVALID_URL
    npm ERR! Invalid URL
    npm ERR! A complete log of this run can be found in: C:\Users\mahya\AppData\Local\npm-cache\_logs\2023-08-31T19_07_41_628Z-debug-0.log```
              

    Hi, @mahya-sh

    Apologize for the delayed response and Could you please run below command and help me with complete error log output after running this command node-gyp configure to investigate your issue further ? Thank you for your patience and understanding

    Please follow below steps :

  • Run npm install -g node-gyp (Install node-gyp globally by using this command)
  • Check node-gyp version using this command node-gyp --version
  • Run node-gyp configure (If you get error messages please share complete error log output to investigate issue further)
  • "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" "dependencies": { "@tensorflow/tfjs-node": "^3.18.0" "author": "", "license": "ISC"

    Even tried adding this postinstall

    "postinstall": "npm rebuild @tensorflow/tfjs-node --build-addon-from-source"
    
    PS C:\Workspace\testing> yarn install
    yarn install v1.22.19
    info No lockfile found.
    [1/4] Resolving packages...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    [2/4] Fetching packages...
    [3/4] Linking dependencies...
    [4/4] Building fresh packages...
    [2/2] ⠈ @tensorflow/tfjs-node
    error C:\Workspace\testing\node_modules\@tensorflow\tfjs-node: Command failed.
    Exit code: 1
    Command: node scripts/install.js
    Arguments:
    Directory: C:\Workspace\testing\node_modules\@tensorflow\tfjs-node
    Output:
    CPU-windows-3.21.1.zip
    * Downloading libtensorflow
    https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-2.9.1.zip
    * Building TensorFlow Node.js bindings
    symlink ./lib/napi-v9 failed:  Error: Command failed: node scripts/deps-stage.js symlink ./lib/napi-v9
      * Symlink of lib\napi-v9\tensorflow.dll failed, creating a copy on disk.
    node:internal/process/promises:288
                triggerUncaughtException(err, true /* fromPromise */);
    [Error: ENOENT: no such file or directory, copyfile 'C:\Workspace\testing\node_modules\@tensorflow\tfjs-node\deps\lib\tensorflow.dll' -> 'C:\Workspace\testing\node_modules\@tensorflow\tfjs-node\lib\napi-v9\tensorflow.dll'] {
      errno: -4058,
      code: 'ENOENT',
      syscall: 'copyfile',
      path: 'C:\\Workspace\\testing\\node_modules\\@tensorflow\\tfjs-node\\deps\\lib\\tensorflow.dll',
      dest: 'C:\\Workspace\\testing\\node_modules\\@tensorflow\\tfjs-node\\lib\\napi-v9\\tensorflow.dll'
    Node.js v18.18.0
        at ChildProcess.exithandler (node:child_process:422:12)
        at ChildProcess.emit (node:events:517:28)
        at maybeClose (node:internal/child_process:1098:16)
        at ChildProcess._handle.onexit (node:internal/child_process:303:5) {
      code: 1,
      killed: false,
      signal: null,
      cmd: 'node scripts/deps-stage.js symlink ./lib/napi-v9'
              

    Realized that all is built properly, but they are placed inside napi-v8 not napi-v9, still don't know how to solve it.

    NodeJS is 18
    Python 2 and 3 installed (2 not exposed to path)
    Visual Studio 2022 and 2019 build tools installed (c/c++ development in both)

    Hi, @iongion

    Good to hear that, your problem solved with Node v18.13.0 (LTS)

    @mahya-sh, I would suggest you to please go with Node v18.17.0 (LTS) and follow the below steps which will resolve your issue. if issue still persists please help us with error log after running this command node-gyp configure to investigate your issue further ? Thank you for your patience and understanding.

  • Edit the path user or system variable, ensure that the path to python is added to the path variable.
  • Install Visual Studio community edition with desktop development with C++ Link
  • Install visual studio build tools with the help of Visual Studio Installer
  • Ensure that node-gyp is available: npm install -g node-gyp
  • Install tfjs-node: npm install @tensorflow/[email protected]
  • 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, you will not be able to use tfjs-node as far I know.

    To check if Windows 10 supports AVX processors:

  • Press Windows + R to open the Run dialog box.
  • Type msinfo32 and press Enter.
  • In the System Information window, expand the Components node and select Processor.
  • In the right pane, look for the Instruction Sets entry. If AVX is listed, then your CPU supports it.
  • Thank you!

    Hi, @mahya-sh

    We haven't heard from you in last couple of weeks so now I'm closing this issue, if someone is facing similar issue with tfjs-node on Windows machine please refer this comment and most of community users are able to install tfjs-node on windows machine after downgrading Node.js version to v18.16.1 with python 3.8 or python 3.9 and try with either npm install --save-exact @tensorflow/[email protected] or npm install --save-exact @tensorflow/[email protected] command

    Closing the issue since it is being tracked in this issue thread #7341 for future update

    If someone is facing some issue with tfjs-node on Windows machine after trying workaround mentioned in the above comment please feel free to create new issue with error log to help you further.

    Thank you for your understanding and patience.

    let model;
    (async () => {
    model = await tf.loadLayersModel('https://kaggle.com/models/google/universal-sentence-encoder/frameworks/TensorFlow1/variations/lite/versions/1');
    console.log('Model loaded');
    })();

    I am trying to implement real-time chat communication, but here I am getting errors, I am using

    const express = require('express');
    const http = require('http');
    const socketIo = require('socket.io');
    const tf = require('@tensorflow/tfjs-node');

    these packages and nodemon to automate any changes, with these version:
    "@tensorflow-models/universal-sentence-encoder": "^1.3.3",
    "@tensorflow/tfjs": "^4.17.0",
    "@tensorflow/tfjs-node": "3.10.0",
    "express": "^4.18.3",
    "express-ws": "^5.0.2",
    "nodemon": "^3.1.0",
    "socket.io": "^4.7.4"

    throw new Error(message);
    Error: Failed to parse model JSON of response from https://kaggle.com/models/google/universal-sentence-encoder/frameworks/TensorFlow1/variations/lite/versions/1. Please make sure the server is serving valid JSON for this request.
    at HTTPRequest. (