node-opencv icon indicating copy to clipboard operation
node-opencv copied to clipboard

Ubuntu npm install opencv issues

Open arimai opened this issue 8 years ago • 6 comments

System : Ubuntu 16.04 LTS
npm : 3.5.2
node : v4.2.6 

When I try to install node-opencv by running 'npm install opencv`, I get a npm warning as follows:

npm WARN lifecycle [email protected]~install: cannot run in wd %s %s (wd=%s) [email protected] node-pre-gyp install --fallback-to-build

The node_modules get created and installed but the opencv module does not have a build directory created. Hence when I try to include it by using require('opencv'), I get this

 Cannot find module
../node_modules/opencv/build/opencv/v5.0.0/Release/node-v46-linux-x64/opencv.node'

I tried cloning the master and running npm install and the same problem persists despite of running `npm build' first. How could I make this work? I have tried on a mac and the same steps work fine. Any help appreciated, Thanks!

Note: opencv is installed correctly on the system. I also have pkg_config installed and a PKG_CONFIG_PATH set to where my opencv.pc exists.

arimai avatar Aug 04 '16 22:08 arimai

+1 same to you~ I can't find any stable installation guide

kikaendeavor avatar Aug 05 '16 03:08 kikaendeavor

I Install Opencv On Ubuntu 14.04 With No Fail, But On CentOS 6.7 got a lot of Problem, and i spent a weak to solve the problem, I write down the script for both OS, may be it can help you.

https://github.com/Josephliao1991/LinuxPackageShell/tree/master/Opencv

Josephliao1991 avatar Aug 07 '16 09:08 Josephliao1991

I installed opencv as node modules success, when I installed gcc-4.8 and g++-4.8.1. so I suggest you have a try.

kikaendeavor avatar Aug 23 '16 06:08 kikaendeavor

I install node_module OpenCv via npm it give error yeoman@yeoman:~/Documents/faceDetection_back$ sudo npm install opencv --save

[email protected] install /home/yeoman/Documents/faceDetection_back/node_modules/opencv node-pre-gyp install --fallback-to-build

/home/yeoman/Documents/faceDetection_back/node_modules/opencv/utils/find-opencv.js:21 throw new Error("ERROR: failed to run: pkg-config", opencv, flag); ^

Error: ERROR: failed to run: pkg-config at /home/yeoman/Documents/faceDetection_back/node_modules/opencv/utils/find-opencv.js:21:23 at ChildProcess.exithandler (child_process.js:213:5) at emitTwo (events.js:106:13) at ChildProcess.emit (events.js:191:7) at maybeClose (internal/child_process.js:877:16) at Socket. (internal/child_process.js:334:11) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at Pipe._handle.close as _onclose gyp: Call to 'node utils/find-opencv.js --cflags' returned exit status 1 while in binding.gyp. while trying to load binding.gyp gyp ERR! configure error gyp ERR! stack Error: gyp failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:305:16) gyp ERR! stack at emitTwo (events.js:106:13) gyp ERR! stack at ChildProcess.emit (events.js:191:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12) gyp ERR! System Linux 4.2.0-36-generic gyp ERR! command "/usr/bin/nodejs" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/home/yeoman/Documents/faceDetection_back/node_modules/opencv/build/opencv/v5.0.0/Release/node-v48-linux-x64/opencv.node" "--module_name=opencv" "--module_path=/home/yeoman/Documents/faceDetection_back/node_modules/opencv/build/opencv/v5.0.0/Release/node-v48-linux-x64" gyp ERR! cwd /home/yeoman/Documents/faceDetection_back/node_modules/opencv gyp ERR! node -v v6.5.0 gyp ERR! node-gyp -v v3.3.1 gyp ERR! not ok node-pre-gyp ERR! build error node-pre-gyp ERR! stack Error: Failed to execute '/usr/bin/nodejs /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/yeoman/Documents/faceDetection_back/node_modules/opencv/build/opencv/v5.0.0/Release/node-v48-linux-x64/opencv.node --module_name=opencv --module_path=/home/yeoman/Documents/faceDetection_back/node_modules/opencv/build/opencv/v5.0.0/Release/node-v48-linux-x64' (1) node-pre-gyp ERR! stack at ChildProcess. (/home/yeoman/Documents/faceDetection_back/node_modules/opencv/node_modules/node-pre-gyp/lib/util/compile.js:83:29) node-pre-gyp ERR! stack at emitTwo (events.js:106:13) node-pre-gyp ERR! stack at ChildProcess.emit (events.js:191:7) node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:877:16) node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) node-pre-gyp ERR! System Linux 4.2.0-36-generic node-pre-gyp ERR! command "/usr/bin/nodejs" "/home/yeoman/Documents/faceDetection_back/node_modules/opencv/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" node-pre-gyp ERR! cwd /home/yeoman/Documents/faceDetection_back/node_modules/opencv node-pre-gyp ERR! node -v v6.5.0 node-pre-gyp ERR! node-pre-gyp -v v0.6.17 node-pre-gyp ERR! not ok Failed to execute '/usr/bin/nodejs /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/yeoman/Documents/faceDetection_back/node_modules/opencv/build/opencv/v5.0.0/Release/node-v48-linux-x64/opencv.node --module_name=opencv --module_path=/home/yeoman/Documents/faceDetection_back/node_modules/opencv/build/opencv/v5.0.0/Release/node-v48-linux-x64' (1) npm WARN [email protected] No description npm WARN [email protected] No repository field. npm ERR! Linux 4.2.0-36-generic npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "opencv" "--save" npm ERR! node v6.5.0 npm ERR! npm v3.10.3 npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: node-pre-gyp install --fallback-to-build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] install script 'node-pre-gyp install --fallback-to-build'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the opencv package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node-pre-gyp install --fallback-to-build npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs opencv npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls opencv npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request: npm ERR! /home/yeoman/Documents/faceDetection_back/npm-debug.log

chandankrishnan avatar Sep 02 '16 04:09 chandankrishnan

My install algo

  1. Delete all from system sudo apt-get remove --purge node nodejs npm node-gyp node-pre-gyp sudo apt-get autoremove
  2. Download and install NVM (Node version manager) I have notice that some times ubuntu have some troubles with nvm when you install things in root mode. Unroot if needed. // check for newest version in git repo curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.7/install.sh | bash
    // Update current terminal source ~/.bashrc // Check nvm version command nvm -v // Check current nvm node versions (must be empty list) nvm ls
  3. Install nodejs // install nodejs needed version (must be > 0.10 for node-opencv i recommend 6.5+) nvm install v6.5.0 // set default node version nvm alias default v6.5.0 // check for instalation 6.5 nvm ls (NPM installs automatic with nvm)
  4. Opencv // install opencv ubuntu library if needed sudo apt-get install libopencv-dev npm -g install node-gyp npm -g install node-pre-gyp npm -g install opencv // or you can install it local and add to package.json //// npm --save install opencv
  5. also recommend install nodemon for developement and supervizor for production

firefred avatar Sep 09 '16 07:09 firefred

There're a few different errors going on here. @firefred has a very detailed list of what to do.

@arimai, you should check node_modules/opencv/build/opencv/v5.0.0/Release. If there's no directories, it means that node-opencv could not be compiled at all, and you might not have OpenCV installed in the first place. If there's a directory, and it's not node-v46-linux-x64, then it means that node-opencv was compiled to a different node/arch setup than what you're using the script with.

@chandankrishnan it sounds like OpenCV has not been installed on your system?

I'll close this thread in some days if there's no follow-up, since there's a few solutions posted already.

danschultzer avatar Oct 01 '16 18:10 danschultzer