opencv4nodejs icon indicating copy to clipboard operation
opencv4nodejs copied to clipboard

Can't install opencv4nodejs

Open SatoshiKawabata opened this issue 4 years ago • 41 comments

  1. I tried to install into RasberryPi.
  2. I installed CMake already
  3. I set
  • export OPENCV4NODEJS_DISABLE_AUTOBUILD=0
  • export OPENCV4NODEJS_AUTOBUILD_OPENCV_VERSION=4.1.0
  1. I tried to install opencv4nodejs via npm i opencv4nodejs
  2. I got the below error.

Error Message

$ npm i opencv4nodejs

> [email protected] install /home/pi/opencv-virtualuvc/node_modules/opencv4nodejs
> node ./install/install.js

info the following opencv4nodejs environment variables are set in the package.json: 
info autoBuildFlags: -DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_PC_FILE_NAME=opencv.pc 
info autoBuildOpencvVersion: 4.1.0 
info install OPENCV_LIB_DIR is not set, looking for default lib dir
info install using lib dir: /usr/local/lib
/home/pi/opencv-virtualuvc/node_modules/opencv4nodejs/install/install.js:45
  throw new Error('no OpenCV libraries found in lib dir: ' + libDir)
  ^

Error: no OpenCV libraries found in lib dir: /usr/local/lib
    at Object.<anonymous> (/home/pi/opencv-virtualuvc/node_modules/opencv4nodejs/install/install.js:45:9)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node ./install/install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pi/.npm/_logs/2020-06-19T22_35_51_386Z-debug.log

Auto Build - Full Error Log

I'd like Auto Build. But I don't know where Auto Build Error Log is.

OpenCV version (example 3.4.1): ?.?.?

With OpenCV-contrib? (extra modules): ?

OS: Raspbian GNU/Linux 10 (buster)

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

SatoshiKawabata avatar Jun 19 '20 22:06 SatoshiKawabata

I am also getting this same error whenever trying to npm install.

blue-codes-yep avatar Jun 25 '20 20:06 blue-codes-yep

throw new Error('no OpenCV libraries found in lib dir: ' + libDir) indicate that it is looking for the libDir-folder which should be set when not using autobuild.

Does the error persist if you unset OPENCV4NODEJS_DISABLE_AUTOBUILD? I experienced that the mere presence of the env variable was interpreted as "truthy" no matter the value.

Edit: Which I have opened a PR to solve - https://github.com/justadudewhohacks/npm-opencv-build/pull/42

FluidSense avatar Jun 29 '20 07:06 FluidSense

unset OPENCV4NODEJS_DISABLE_AUTOBUILD

This seemed to resolve this particular issue for me. Thank you :+1:

ToeFungi avatar Jul 18 '20 14:07 ToeFungi

As someone mentioned in one of the previous issues, manually building it worked for me.

First, go to the corresponding directory.

cd node_modules/opencv4nodejs/build

Then build manually.

make

Finally, add this to your package.json file, inside your "scripts"

"postinstall": "cd node_modules/opencv4nodejs/build; make"

I believe the problem is caused by a faulty autobuild.

emrullahjack avatar Sep 15 '20 22:09 emrullahjack

I got solution.

Don't try to run npm from any of C:/Windows/... folder inside Windows

YZBhushan avatar Jan 02 '21 06:01 YZBhushan

specify environment variables or add them to the package.json

"dependencies": {
  "opencv4nodejs": "^5.6.0"
},
"opencv4nodejs": {
  "disableAutoBuild": 1,
  "opencvIncludeDir": "C:\\tools\\opencv\\build\\include",
  "opencvLibDir": "C:\\tools\\opencv\\build\\x64\\vc14\\lib",
  "opencvBinDir": "C:\\tools\\opencv\\build\\x64\\vc14\\bin"
},

24bulut avatar May 16 '21 00:05 24bulut

Where can I find this> unset OPENCV4NODEJS_DISABLE_AUTOBUILD

JahangirJadiKD avatar Jul 10 '21 06:07 JahangirJadiKD

Where can I find this> unset OPENCV4NODEJS_DISABLE_AUTOBUILD

Just type unset OPENCV4NODEJS_DISABLE_AUTOBUILD in your terminal where you try to install opencv4nodejs

FluidSense avatar Jul 12 '21 08:07 FluidSense

the same issue here path /Users/mohamedgamal/node_modules/opencv4nodejs npm ERR! command failed npm ERR! command sh -c node ./install/install.js npm ERR! info install OPENCV_LIB_DIR is not set, looking for default lib dir npm ERR! info install using lib dir: /usr/local/lib npm ERR! /Users/mohamedgamal/node_modules/opencv4nodejs/install/install.js:45 npm ERR! throw new Error('no OpenCV libraries found in lib dir: ' + libDir) npm ERR! ^ npm ERR! npm ERR! Error: no OpenCV libraries found in lib dir: /usr/local/lib npm ERR! at Object. (/Users/mohamedgamal/node_modules/opencv4nodejs/install/install.js:45:9) npm ERR! at Module._compile (node:internal/modules/cjs/loader:1101:14) npm ERR! at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) npm ERR! at Module.load (node:internal/modules/cjs/loader:981:32) npm ERR! at Function.Module._load (node:internal/modules/cjs/loader:822:12) npm ERR! at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12) npm ERR! at node:internal/main/run_main_module:17:47

npm ERR! A complete log of this run can be found in:

mohamed8681 avatar Aug 19 '21 23:08 mohamed8681

I am receiving this error as well, on the latest macos. Issuing unset OPENCV4NODEJS_DISABLE_AUTOBUILD does not seem to have any affect.

jabberwock avatar Sep 03 '21 23:09 jabberwock

is there any fix for this issue? I am doing unset OPENCV4NODEJS_DISABLE_AUTOBUILD as well and it is still failing

$ npm i -g opencv4nodejs
npm ERR! code 1
npm ERR! path /opt/homebrew/lib/node_modules/opencv4nodejs
npm ERR! command failed
npm ERR! command sh -c node ./install/install.js
npm ERR! info install using lib dir: /opt/homebrew/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/build/lib
npm ERR! /opt/homebrew/lib/node_modules/opencv4nodejs/install/install.js:37
npm ERR!   throw new Error('library dir does not exist: ' + libDir)
npm ERR!   ^
npm ERR! 
npm ERR! Error: library dir does not exist: /opt/homebrew/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/build/lib
npm ERR!     at Object.<anonymous> (/opt/homebrew/lib/node_modules/opencv4nodejs/install/install.js:37:9)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:981:32)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
npm ERR!     at node:internal/main/run_main_module:17:47

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/fbernaly/.npm/_logs/2021-09-17T20_17_41_740Z-debug.log

fbernaly avatar Sep 17 '21 20:09 fbernaly

Is there a genuine solution to this problem? I cannot find the opencv4nodejs under lib/node_modules PS: I'm using Linuxbrew on Ubuntu 20.0.04

ammaramja avatar Sep 24 '21 07:09 ammaramja

Fedora 34, same issue

[user@user-pc cardet]$ npm install --save opencv4nodejs
npm ERR! code 1
npm ERR! path /home/user/WebstormProjects/cardet/node_modules/opencv4nodejs
npm ERR! command failed
npm ERR! command sh -c node ./install/install.js
npm ERR! info install using lib dir: /home/user/WebstormProjects/cardet/node_modules/opencv-build/opencv/build/lib
npm ERR! /home/user/WebstormProjects/cardet/node_modules/opencv4nodejs/install/install.js:37
npm ERR!   throw new Error('library dir does not exist: ' + libDir)
npm ERR!   ^
npm ERR! 
npm ERR! Error: library dir does not exist: /home/user/WebstormProjects/cardet/node_modules/opencv-build/opencv/build/lib
npm ERR!     at Object.<anonymous> (/home/user/WebstormProjects/cardet/node_modules/opencv4nodejs/install/install.js:37:9)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1095:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:975:32)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:816:12)
npm ERR!     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
npm ERR!     at node:internal/main/run_main_module:17:47

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2021-10-12T13_29_52_707Z-debug.log

vdakalov avatar Oct 12 '21 13:10 vdakalov

I have done the manual installation steps and was able to make it work: https://github.com/justadudewhohacks/opencv4nodejs#installing-opencv-manually

  1. Install Chocolatey
  2. Open cmd and set his env variable set OPENCV4NODEJS_DISABLE_AUTOBUILD=1
  3. Install OpenCV with this command: choco install OpenCV -y -version 4.1.0

By default it installed OpenCV on my C:\tools folder, so change the folders below according to your needs

  1. Set more env vars: set OPENCV_INCLUDE_DIR=C:\tools\opencv\build\include set OPENCV_LIB_DIR=C:\tools\opencv\build\x64\vc15\lib set OPENCV_BIN_DIR=C:\tools\opencv\build\x64\vc15\bin set PATH=%PATH%;%OPENCV_BIN_DIR%; set OPENCV4NODEJS_AUTOBUILD_OPENCV_VERSION=4.1.0
  2. Run npm i -g --save opencv4nodejs

With this I was able to get a successful installation of opencv4nodejs.

I did this installation to be able to use Appium findByImage feature, if you are trying to achieve the same then you might face more issues as I did, I was also able to get those solved but I did so much digging that I can't remember every step I've done, but I found the problem was that node was having an issue finding the location of opencv in modules.

If you wanna do a quick check if you opencv is properly installed, create a project with the following content:

root/node_modules/
root/app.js

On app.js enter the following:

let opencv = require('opencv4nodejs');
console.log("success")

Then try to run this using node: node app.js, if it works then you just need to do the npm link between appium and opencv4nodejs.

Jiwari avatar Oct 18 '21 18:10 Jiwari

I am facing the same installation failure issue in mac. Can someone please guide me on how to install opencv4nodejs in MAC device? Error log: code 1 npm ERR! path /Users/mac/node_modules/opencv4nodejs npm ERR! command failed npm ERR! command sh -c node ./install/install.js npm ERR! info install using lib dir: /Users/mac/node_modules/opencv-build/opencv/build/lib npm ERR! /Users/mac/node_modules/opencv4nodejs/install/install.js:37 npm ERR! throw new Error('library dir does not exist: ' + libDir) npm ERR! ^ npm ERR! npm ERR! Error: library dir does not exist: /Users/mac/node_modules/opencv-build/opencv/build/lib

chitta-ghosh avatar Oct 19 '21 13:10 chitta-ghosh

node

i got this error too, and spent almost one day to search and try solutions for that, but i failed to solve the error.

SCUTBrothers avatar Oct 20 '21 08:10 SCUTBrothers

node

i got this error too, and spent almost one day to search and try solutions for that, but i failed to solve the error.

First, install opencv on your machine apt install libopencv-dev python3-opencv

Second, checking if opencv is avaiable

python3
import cv2 as cv
print(cv.__version__)

Then install opencv4nodejs

sudo npm install opencv4nodejs --save

mozaa-vn avatar Oct 20 '21 15:10 mozaa-vn

I have done the manual installation steps and was able to make it work: https://github.com/justadudewhohacks/opencv4nodejs#installing-opencv-manually

  1. Install Chocolatey
  2. Open cmd and set his env variable set OPENCV4NODEJS_DISABLE_AUTOBUILD=1
  3. Install OpenCV with this command: choco install OpenCV -y -version 4.1.0

By default it installed OpenCV on my C:\tools folder, so change the folders below according to your needs

  1. Set more env vars: set OPENCV_INCLUDE_DIR=C:\tools\opencv\build\include set OPENCV_LIB_DIR=C:\tools\opencv\build\x64\vc15\lib set OPENCV_BIN_DIR=C:\tools\opencv\build\x64\vc15\bin set PATH=%PATH%;%OPENCV_BIN_DIR%; set OPENCV4NODEJS_AUTOBUILD_OPENCV_VERSION=4.1.0
  2. Run npm i -g --save opencv4nodejs

With this I was able to get a successful installation of opencv4nodejs.

I did this installation to be able to use Appium findByImage feature, if you are trying to achieve the same then you might face more issues as I did, I was also able to get those solved but I did so much digging that I can't remember every step I've done, but I found the problem was that node was having an issue finding the location of opencv in modules.

If you wanna do a quick check if you opencv is properly installed, create a project with the following content:

root/node_modules/
root/app.js

On app.js enter the following:

let opencv = require('opencv4nodejs');
console.log("success")

Then try to run this using node: node app.js, if it works then you just need to do the npm link between appium and opencv4nodejs.

Everyone who is coming to this at a later date this is the only working solution I found

Deepankar1993 avatar Nov 08 '21 09:11 Deepankar1993

As my researching, there are no dylib files in node_modules/opencv-build/opencv/build/lib folder on my MacOS. That is the reason why we get no OpenCV libraries found in lib dir error message. When I use brew to install opencv, dylib files exist.

zcmgyu avatar Dec 08 '21 15:12 zcmgyu

My steps for Mac using Intel chip

  1. brew install opencv
  2. export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
  3. npm i -g opencv4nodejs

Worked fine, using node v16.13.1

ncoma avatar Dec 14 '21 19:12 ncoma

Must linux version install opencv on /usr/lib folder instead of /usr/local/lib. And the opencv-build dont´t autodetect folder from cmake files installed by opencv.

Maybe a quick solution just inform the environment variable OPENCV_LIB_DIR according to the opencv4nodejs documentation.

For me, this solution solved the problem.

export OPENCV_LIB_DIR=/usr/lib && export OPENCV4NODEJS_DISABLE_AUTOBUILD=1 && npm install opencv4nodejs

Piemontez avatar Jan 04 '22 12:01 Piemontez

My steps for Mac using Intel chip

  1. brew install opencv
  2. export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
  3. npm i -g opencv4nodejs

Worked fine, using node v16.13.1

worked fine for me on mac M1, thanks!

douglas-oliveira-tc avatar Apr 05 '22 21:04 douglas-oliveira-tc

My steps for Mac using Intel chip

  1. brew install opencv
  2. export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
  3. npm i -g opencv4nodejs

Worked fine, using node v16.13.1

worked fine for me on mac M1, thanks!

this does not work for me in my mac monterary

amar1989 avatar Jun 04 '22 09:06 amar1989

My steps for Mac using Intel chip

  1. brew install opencv
  2. export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
  3. npm i -g opencv4nodejs

Worked fine, using node v16.13.1

worked fine for me on mac M1, thanks!

doesn't work on my m1 monterey too

t1nkt35t avatar Jun 15 '22 15:06 t1nkt35t

Is this issue solved?

gilzonme avatar Sep 12 '22 14:09 gilzonme

at least it works with my fork, but you should only use a prebuilt openCV (the one from brew working fine) building from source is complicated due to the FFmpeg 5 compatibility issue.

UrielCh avatar Sep 13 '22 21:09 UrielCh

Must linux version install opencv on /usr/lib folder instead of /usr/local/lib. And the opencv-build dont´t autodetect folder from cmake files installed by opencv.

Maybe a quick solution just inform the environment variable OPENCV_LIB_DIR according to the opencv4nodejs documentation.

For me, this solution solved the problem.

export OPENCV_LIB_DIR=/usr/lib && export OPENCV4NODEJS_DISABLE_AUTOBUILD=1 && npm install opencv4nodejs

That solved my issue except for the path to my lib folder was at /opt/homebrew/lib

OlegBuch avatar Sep 15 '22 11:09 OlegBuch

the code is here it look for open CV in /opt/homebrew/Cellar/opencv/* if you are using a standard setup, I can add a new search path.

UrielCh avatar Sep 15 '22 11:09 UrielCh

Personally, I don't think we should use open cv with nodejs. It's a hectic job to set up it. I would prefer opencv with python.

JahangirJadi avatar Sep 22 '22 10:09 JahangirJadi

specify environment variables or add them to the package.json

"dependencies": {
  "opencv4nodejs": "^5.6.0"
},
"opencv4nodejs": {
  "disableAutoBuild": 1,
  "opencvIncludeDir": "C:\\tools\\opencv\\build\\include",
  "opencvLibDir": "C:\\tools\\opencv\\build\\x64\\vc14\\lib",
  "opencvBinDir": "C:\\tools\\opencv\\build\\x64\\vc14\\bin"
},

This was the one that worked for me did "npm install robotjs" first to get the framework file then removed the "node_modules" replaced package.json content with { "opencv4nodejs": { "disableAutoBuild": 1, "opencvIncludeDir": "C:\tools\opencv\build\include", "opencvLibDir": "C:\tools\opencv\build\x64\vc14\lib", "opencvBinDir": "C:\tools\opencv\build\x64\vc14\bin" }, "dependencies": { "opencv4nodejs": "^5.6.0" } } and after that I ran "npm install opencv4nodejs" and it got downloaded in 3m. Download opencv from a website and make those tools/opencv.... system variables to make it all work. Hopefully this helped anyone.

Bhcfg avatar Apr 07 '23 02:04 Bhcfg