3

I would like to install OpenCV in windows to get the library in NodeJS. But I am recurrently having some issues.

Failed at the OpenCV@5.0.0 install "node-pre-gyp install --fallback-to-build.

This is most likely a problem with opencv package.

What is the way to get the Peterbraden package installed with avoiding this error message? Command is npm install opencv.

Below is the output in a file after running command:

opencv@5.0.0 install C:\node_modules\opencv node-pre-gyp install --fallback-to-build

C:\node_modules\opencv>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" clean ) else (node "" clean )

C:\node_modules\opencv>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" configure --fallback-to-build --module=C:\node_modules\opencv\build\opencv\v5.0.0\Release\node-v46-win32-ia32\opencv.node --module_name=opencv --module_path=C:\node_modules\opencv\build\opencv\v5.0.0\Release\node-v46-win32-ia32 ) else (node "" configure --fallback-to-build --module=C:\node_modules\opencv\build\opencv\v5.0.0\Release\node-v46-win32-ia32\opencv.node --module_name=opencv --module_path=C:\node_modules\opencv\build\opencv\v5.0.0\Release\node-v46-win32-ia32 ) Failed to execute 'node-gyp.cmd configure --fallback-to-build --module=C:\node_modules\opencv\build\opencv\v5.0.0\Release\node-v46-win32-ia32\opencv.node --module_name=opencv --module_path=C:\node_modules\opencv\build\opencv\v5.0.0\Release\node-v46-win32-ia32' (1)

Aleksander Azizi
  • 9,829
  • 9
  • 59
  • 87
Abir Khan
  • 103
  • 1
  • 9

2 Answers2

0

I had similar issues even using virtual boxes prepared to be used with OpenCV and node.js - both Vagrant and Docker.

After few sleepless nights I somehow figured out what was wrong on my machines. First I tried to figure out if OpenCV is installed and where. I was troubleshooting on Linux (Centos) and on Mac OS X.

Solution for me was:

  • install OpenCV libraries
  • add environment variables PKG_CONFIG_PATH with path to file /opencv.pc .../opencv/lib/pkgconfig
  • make sure pkg-config was installed

Ok that was Unix systems. Windows are a bit different but checklist is probably about the same.

  1. OpenCV installed
  2. System environment variables set: As described in documentation you need to set system variables.

That can be done in Computer > Properties > Advanced System Settings

In System properties windows click Advanced tab and then Environment Variables button.

In Environment Variables add to System Properties:

OPENCV_DIR with value: C:\OpenCV\build\x64\vc12
PATH append to your path: ;%OPENCV_DIR%\bin

  1. Build tools installed Make sure Visual Studio installed with C++ compnents!

If all above is check, then perhaps you can also check if pkg config is installed: How to install pkg config in windows?

Hope this helps.

Community
  • 1
  • 1
Erik Ušaj
  • 159
  • 6
0

I ran into this same issue yesterday. I believe the build script is no longer properly installing node-gyp and node-pre-gyp. Here are the steps I completed to resolve the build errors. These steps force the installation of both of those dependencies both globally and at the project level.

  1. Be sure you only have python 2.7 installed on you machine and that is an environment var
  2. you need to global 'npm i -g node-gyp node-pre-gyp'
  3. in terminal/cli/powershell, navigate to the node-opencv project
  4. need to project 'npm i -S node-gyp node-pre-gyp'
  5. npm install (to build the project)
  6. in terminal/cli/powershell to the target/consuming project
  7. 'npm i -S node-gyp node-pre-gyp'
  8. finally, 'npm -i -S opencv'

Hope you have the same success I did.

F.H.
  • 1,456
  • 1
  • 20
  • 34
  • It is both 'node-gyp' AND 'node-pre-gyp'. Both of these must be installed globally and within the project. You may install both in one shot be entering what I have suggested. That is, type 'npm i -g node-gyp node-pre-gyp' into your terminal/cli. – user2340578 Oct 03 '16 at 15:01