peterbraden / node-opencv

OpenCV Bindings for node.js
MIT License
4.37k stars 858 forks source link

[BUG] Cannot Install opencv js with npm (windows 10/ubuntu 20.04) #677

Open MarkKocherovsky opened 3 years ago

MarkKocherovsky commented 3 years ago

Describe the bug When running sudo npm i opencv, I get the following error:

mkocherov@R9301986:/mnt/c/Users/mkocherov/Documents/Scratch/SrPrj2/scratch-vm/src/extensions/scratch3_palmreader$ sudo npm install opencv
npm ERR! code 1
npm ERR! path /mnt/c/Users/mkocherov/Documents/Scratch/SrPrj2/scratch-vm/node_modules/opencv
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@15.6.0 | linux | x64
npm ERR! gyp info find Python using Python version 3.8.5 found at "/usr/bin/python3"
npm ERR! gyp WARN EACCES current user ("mkocherov") does not have permission to access the dev dir "/root/.cache/node-gyp/15.6.0"
npm ERR! gyp WARN EACCES attempting to reinstall using temporary dev dir "/tmp/.node-gyp"
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/mnt/c/Users/mkocherov/Documents/Scratch/SrPrj2/scratch-vm/node_modules/opencv/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/tmp/.node-gyp/15.6.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/tmp/.node-gyp/15.6.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/usr/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/tmp/.node-gyp/15.6.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/mnt/c/Users/mkocherov/Documents/Scratch/SrPrj2/scratch-vm/node_modules/opencv',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! /mnt/c/Users/mkocherov/Documents/Scratch/SrPrj2/scratch-vm/node_modules/opencv/utils/find-opencv.js:29
npm ERR!      throw new Error("ERROR: failed to run: pkg-config" + opencv + " " + flag + " - Is OpenCV installed?");
npm ERR!
npm ERR!
npm ERR! Error: ERROR: failed to run: pkg-config "opencv >= 2.3.1" --cflags - Is OpenCV installed?
npm ERR!     at /mnt/c/Users/mkocherov/Documents/Scratch/SrPrj2/scratch-vm/node_modules/opencv/utils/find-opencv.js:29:21
npm ERR!     at ChildProcess.exithandler (node:child_process:340:5)
npm ERR!     at ChildProcess.emit (node:events:379:20)
npm ERR!     at maybeClose (node:internal/child_process:1065:16)
npm ERR!     at Process.ChildProcess._handle.onexit (node:internal/child_process:296:5)
npm ERR! gyp: Call to 'node utils/find-opencv.js --cflags' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:379:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:285:12)
npm ERR! gyp ERR! System Linux 4.4.0-17763-Microsoft
npm ERR! gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /mnt/c/Users/mkocherov/Documents/Scratch/SrPrj2/scratch-vm/node_modules/opencv
npm ERR! gyp ERR! node -v v15.6.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-03-17T17_18_10_483Z-debug.log

I have pkg-config installed. I also have opencv installed on windows, added to my PATH and my new system variable, and the git is cloned in my project directory. I'm currently running npm 7.6.0 on the Ubuntu 20.04 terminal for windows 10.

To Reproduce Follow the windows instructions here and run sudo npm i opencv in the project directory. Expected behavior Should Install opencv js with no errors.

OS / Libraries

Additional context

If I run apt list | grep opencv, the following is returned:

mkocherov@R9301986:/mnt/c/Users/mkocherov/Documents/Scratch/SrPrj2/scratch-gui$ aptlist | grepopencv
WARNING:apt does not have a stable CLI interface. Use with caution in scripts.
cl-opencv-apps/focal1.12.0-3build3all
gstreamer1.0-opencv/focal1.16.2-2.1ubuntu1amd64
libgstreamer-opencv1.0-0/focal1.16.2-2.1ubuntu1amd64
libopencv-apps-dev/focal1.12.0-3build3amd64
libopencv-apps1d/focal1.12.0-3build3amd64
libopencv-calib3d-dev/focal4.2.0+dfsg-5amd64
libopencv-calib3d4.2/focal4.2.0+dfsg-5amd64
libopencv-contrib-dev/focal4.2.0+dfsg-5amd64
libopencv-contrib4.2/focal4.2.0+dfsg-5amd64
libopencv-core-dev/focal4.2.0+dfsg-5amd64
libopencv-core4.2/focal4.2.0+dfsg-5amd64
libopencv-dev/focal4.2.0+dfsg-5amd64
libopencv-dnn-dev/focal4.2.0+dfsg-5amd64
libopencv-dnn4.2/focal4.2.0+dfsg-5amd64
libopencv-features2d-dev/focal4.2.0+dfsg-5amd64
libopencv-features2d4.2/focal4.2.0+dfsg-5amd64
libopencv-flann-dev/focal4.2.0+dfsg-5amd64
libopencv-flann4.2/focal4.2.0+dfsg-5amd64
libopencv-highgui-dev/focal4.2.0+dfsg-5amd64
libopencv-highgui4.2/focal4.2.0+dfsg-5amd64
libopencv-imgcodecs-dev/focal4.2.0+dfsg-5amd64
libopencv-imgcodecs4.2/focal4.2.0+dfsg-5amd64
libopencv-imgproc-dev/focal4.2.0+dfsg-5amd64
libopencv-imgproc4.2/focal4.2.0+dfsg-5amd64
libopencv-ml-dev/focal4.2.0+dfsg-5amd64
libopencv-ml4.2/focal4.2.0+dfsg-5amd64
libopencv-objdetect-dev/focal4.2.0+dfsg-5amd64
libopencv-objdetect4.2/focal4.2.0+dfsg-5amd64
libopencv-photo-dev/focal4.2.0+dfsg-5amd64
libopencv-photo4.2/focal4.2.0+dfsg-5amd64
libopencv-shape-dev/focal4.2.0+dfsg-5amd64
libopencv-shape4.2/focal4.2.0+dfsg-5amd64
libopencv-stitching-dev/focal4.2.0+dfsg-5amd64
libopencv-stitching4.2/focal4.2.0+dfsg-5amd64
libopencv-superres-dev/focal4.2.0+dfsg-5amd64
libopencv-superres4.2/focal4.2.0+dfsg-5amd64
libopencv-ts-dev/focal4.2.0+dfsg-5amd64
libopencv-video-dev/focal4.2.0+dfsg-5amd64
libopencv-video4.2/focal4.2.0+dfsg-5amd64
libopencv-videoio-dev/focal4.2.0+dfsg-5amd64
libopencv-videoio4.2/focal4.2.0+dfsg-5amd64
libopencv-videostab-dev/focal4.2.0+dfsg-5amd64
libopencv-videostab4.2/focal4.2.0+dfsg-5amd64
libopencv-viz-dev/focal4.2.0+dfsg-5amd64
libopencv-viz4.2/focal4.2.0+dfsg-5amd64
libopencv4.2-java/focal4.2.0+dfsg-5all
libopencv4.2-jni/focal4.2.0+dfsg-5amd64
node-opencv/focal6.0.0+git20190322.db093cb2-7amd64
opencv-data/focal4.2.0+dfsg-5all
opencv-doc/focal4.2.0+dfsg-5all
python3-opencv-apps/focal1.12.0-3build3all
python3-opencv/focal4.2.0+dfsg-5amd64
ros-opencv-apps/focal1.12.0-3build3amd64
s3fs commented 3 years ago

I've got the same issue. I'm on Ubuntu and I've built and installed opencv from source according to their instructions. Can't install this package though. Any updates/solutions on this issue? TIA.

vanga commented 2 years ago

I am not sure where the problem is, but the way this library is looking to find opencv is not working.

opencv4 is what is present. looking at this script, setting this env variable (PKG_CONFIG_OPENCV4=1) can force this module to look for opencv4. That got me past the npm installation.

jalcine-cfa commented 1 year ago

I am not sure where the problem is, but the way this library is looking to find opencv is not working.

opencv4 is what is present. looking at this script, setting this env variable (PKG_CONFIG_OPENCV4=1) can force this module to look for opencv4. That got me past the npm installation.

Using this got me up to here:

npm ERR! code 1
npm ERR! path /Users/jackyalcine/Projects/vita-min/node_modules/opencv
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! CXX(target) Release/obj.target/opencv/src/init.o
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.3.1
npm ERR! gyp info using node@18.16.0 | darwin | arm64
npm ERR! gyp info find Python using Python version 3.11.4 found at "/opt/homebrew/opt/python@3.11/bin/python3.11"
npm ERR! gyp info spawn /opt/homebrew/opt/python@3.11/bin/python3.11
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/opt/homebrew/Cellar/node@18/18.16.0_1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/jackyalcine/Projects/vita-min/node_modules/opencv/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/opt/homebrew/Cellar/node@18/18.16.0_1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/jackyalcine/Library/Caches/node-gyp/18.16.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/jackyalcine/Library/Caches/node-gyp/18.16.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/opt/homebrew/Cellar/node@18/18.16.0_1/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/jackyalcine/Library/Caches/node-gyp/18.16.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/jackyalcine/Projects/vita-min/node_modules/opencv',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from ../src/init.cc:1:
npm ERR! In file included from ../src/OpenCV.h:18:
npm ERR! In file included from /Users/jackyalcine/Library/Caches/node-gyp/18.16.0/include/node/v8.h:24:
npm ERR! In file included from /Users/jackyalcine/Library/Caches/node-gyp/18.16.0/include/node/v8-array-buffer.h:12:
npm ERR! In file included from /Users/jackyalcine/Library/Caches/node-gyp/18.16.0/include/node/v8-local-handle.h:12:
npm ERR! /Users/jackyalcine/Library/Caches/node-gyp/18.16.0/include/node/v8-internal.h:646:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
npm ERR!             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR!                                 ~~~~~^~~~~~~~~~~
npm ERR!                                      remove_cv
npm ERR! /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__type_traits/remove_cv.h:22:50: note: 'remove_cv' declared here
npm ERR! template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
npm ERR!                                                  ^
npm ERR! ../src/init.cc:23:9: warning: Building with OpenCV4.7 [-W#pragma-messages]
npm ERR! #pragma message ( "Building with OpenCV" STR(CV_MAJOR_VERSION) "." STR(CV_MINOR_VERSION) )
npm ERR!         ^
npm ERR! 1 warning and 1 error generated.
npm ERR! make: *** [Release/obj.target/opencv/src/init.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/opt/homebrew/Cellar/node@18/18.16.0_1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:203:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Darwin 22.5.0
npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node@18/18.16.0_1/bin/node" "/opt/homebrew/Cellar/node@18/18.16.0_1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/jackyalcine/Projects/vita-min/node_modules/opencv
npm ERR! gyp ERR! node -v v18.16.0
npm ERR! gyp ERR! node-gyp -v v9.3.1
npm ERR! gyp ERR! not ok