Skip to content

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

@MarkKocherovsky

Description

@MarkKocherovsky

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 [email protected]
npm ERR! gyp info using [email protected] | 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

  • Windows 10/Ubuntu 20.04 Terminal/npm 7.6.0
  • Latest (as of 17 March 2021), hopefully

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions