Calmery.me

みっかぼうずにならないようがんばる

npm installで起こるnode-gypのエラーの対処方法

忘れそうなのでメモ.npm install すると node-gyp のエラーが出た.

$ npm install opencv

> opencv@6.0.0 install /Users/calmery/projects/opencv/node_modules/opencv
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download(403): https://node-opencv.s3.amazonaws.com/opencv/v6.0.0/Release/node-v51-darwin-x64.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for opencv@6.0.0 and node@7.1.0 (node-v51 ABI) (falling back to source compile with node-gyp) 
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /Users/calmery/.pyenv/shims/python2 -c import platform; print(platform.python_version());
gyp ERR! stack pyenv: python2: command not found
gyp ERR! stack 
gyp ERR! stack The `python2' command exists in these Python versions:
gyp ERR! stack   2.7.12
gyp ERR! stack 
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:211:12)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:885:16)
gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:334:11)
gyp ERR! stack     at emitOne (events.js:96:13)
gyp ERR! stack     at Socket.emit (events.js:188:7)
gyp ERR! stack     at Pipe._handle.close [as _onclose] (net.js:501:12)
gyp ERR! System Darwin 15.6.0
gyp ERR! command "/usr/local/bin/node" "/Users/calmery/projects/opencv/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/calmery/projects/opencv/node_modules/opencv/build/opencv/v6.0.0/Release/node-v51-darwin-x64/opencv.node" "--module_name=opencv" "--module_path=/Users/calmery/projects/opencv/node_modules/opencv/build/opencv/v6.0.0/Release/node-v51-darwin-x64"
gyp ERR! cwd /Users/calmery/projects/opencv/node_modules/opencv
gyp ERR! node -v v7.1.0
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /Users/calmery/projects/opencv/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/calmery/projects/opencv/node_modules/opencv/build/opencv/v6.0.0/Release/node-v51-darwin-x64/opencv.node --module_name=opencv --module_path=/Users/calmery/projects/opencv/node_modules/opencv/build/opencv/v6.0.0/Release/node-v51-darwin-x64' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/calmery/projects/opencv/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:885:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
node-pre-gyp ERR! System Darwin 15.6.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/calmery/projects/opencv/node_modules/opencv/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/calmery/projects/opencv/node_modules/opencv
node-pre-gyp ERR! node -v v7.1.0
node-pre-gyp ERR! node-pre-gyp -v v0.6.32
node-pre-gyp ERR! not ok 
Failed to execute '/usr/local/bin/node /Users/calmery/projects/opencv/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/calmery/projects/opencv/node_modules/opencv/build/opencv/v6.0.0/Release/node-v51-darwin-x64/opencv.node --module_name=opencv --module_path=/Users/calmery/projects/opencv/node_modules/opencv/build/opencv/v6.0.0/Release/node-v51-darwin-x64' (1)
npm WARN enoent ENOENT: no such file or directory, open '/Users/calmery/projects/opencv/package.json'
npm WARN a No description
npm WARN a No repository field.
npm WARN a No README data
npm WARN a No license field.
npm WARN In opencv@6.0.0 replacing bundled version of node-pre-gyp with node-pre-gyp@0.6.32
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "opencv"
npm ERR! node v7.1.0
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE

npm ERR! opencv@6.0.0 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the opencv@6.0.0 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!     /Users/calmery/projects/opencv/npm-debug.log

Windowsでnpm installしてnode-gypでつまずいた時対処方法 - Qiita によると

pythonも必要らしい。
そしてpython3.x系は未対応ということなので2.7系をインストールする。

ということみたい.

$ pyenv local 2.7.12
$ npm install opencv

> opencv@6.0.0 install /Users/calmery/projects/opencv/node_modules/opencv
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download(403): https://node-opencv.s3.amazonaws.com/opencv/v6.0.0/Release/node-v51-darwin-x64.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for opencv@6.0.0 and node@7.1.0 (node-v51 ABI) (falling back to source compile with node-gyp) 
  CXX(target) Release/obj.target/opencv/src/init.o
  CXX(target) Release/obj.target/opencv/src/Matrix.o
../src/Matrix.cc:335:59: warning: 'NewInstance' is deprecated
      [-Wdeprecated-declarations]
  v8::Local<v8::Object> actualBuffer = bufferConstructor->NewInstance(3...
                                                          ^
/Users/calmery/.node-gyp/7.1.0/include/node/v8.h:3288:31: note: 'NewInstance'
      has been explicitly marked deprecated here
                Local<Object> NewInstance(int argc, Local<Value> argv[]) const);
                              ^
...
                                                                   ^
/Users/calmery/.node-gyp/7.1.0/include/node/v8.h:3292:52: note: 'NewInstance'
      has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
                                                   ^
2 warnings generated.
  SOLINK_MODULE(target) Release/opencv.node
  COPY /Users/calmery/projects/opencv/node_modules/opencv/build/opencv/v6.0.0/Release/node-v51-darwin-x64/opencv.node
  TOUCH Release/obj.target/action_after_build.stamp
  CXX(target) Release/obj.target/test_nativemat/test/nativemat.o
  SOLINK_MODULE(target) Release/test_nativemat.node
/Users/calmery/projects/a
└─┬ opencv@6.0.0 
  ├── buffers@0.1.1 
  ├─┬ istanbul@0.4.5 
  │ ├── async@1.5.2 
  │ ├─┬ escodegen@1.8.1 
  │ │ ├── estraverse@1.9.3 
  │ │ ├── esutils@2.0.2 
  │ │ ├─┬ optionator@0.8.2 
  │ │ │ ├── deep-is@0.1.3 
  │ │ │ ├── fast-levenshtein@2.0.6 
  │ │ │ ├── levn@0.3.0 
  │ │ │ ├── prelude-ls@1.1.2 
  │ │ │ └── type-check@0.3.2 
  │ │ └─┬ source-map@0.2.0 
  │ │   └── amdefine@1.0.1 
  │ ├── esprima@2.7.3 
  │ ├── glob@5.0.15 
  │ ├─┬ handlebars@4.0.6 
  │ │ ├─┬ optimist@0.6.1 
  │ │ │ └── wordwrap@0.0.3 
  │ │ ├── source-map@0.4.4 
  │ │ └─┬ uglify-js@2.7.5 
  │ │   ├── async@0.2.10 
  │ │   ├── source-map@0.5.6 
  │ │   ├── uglify-to-browserify@1.0.2 
  │ │   └─┬ yargs@3.10.0 
  │ │     ├── camelcase@1.2.1 
  │ │     ├─┬ cliui@2.1.0 
  │ │     │ ├─┬ center-align@0.1.3 
  │ │     │ │ ├─┬ align-text@0.1.4 
  │ │     │ │ │ ├─┬ kind-of@3.1.0 
  │ │     │ │ │ │ └── is-buffer@1.1.4 
  │ │     │ │ │ ├── longest@1.0.1 
  │ │     │ │ │ └── repeat-string@1.6.1 
  │ │     │ │ └── lazy-cache@1.0.4 
  │ │     │ ├── right-align@0.1.3 
  │ │     │ └── wordwrap@0.0.2 
  │ │     ├── decamelize@1.2.0 
  │ │     └── window-size@0.1.0 
  │ ├─┬ js-yaml@3.7.0 
  │ │ └─┬ argparse@1.0.9 
  │ │   └── sprintf-js@1.0.3 
  │ ├── resolve@1.1.7 
  │ ├─┬ supports-color@3.1.2 
  │ │ └── has-flag@1.0.0 
  │ └── wordwrap@1.0.0 
  ├── nan@2.5.0 
  └─┬ node-pre-gyp@0.6.32 
    ├─┬ rc@1.1.6 
    │ ├── deep-extend@0.4.1 
    │ ├── ini@1.3.4 
    │ ├── minimist@1.2.0 
    │ └── strip-json-comments@1.0.4 
    └─┬ tar-pack@3.3.0 
      ├─┬ debug@2.2.0 
      │ └── ms@0.7.1 
      ├── fstream-ignore@1.0.5 
      ├── once@1.3.3 
      ├── readable-stream@2.1.5 
      └── uid-number@0.0.6 

npm WARN enoent ENOENT: no such file or directory, open '/Users/calmery/projects/opencv/package.json'
npm WARN a No description
npm WARN a No repository field.
npm WARN a No README data
npm WARN a No license field.
npm WARN In opencv@6.0.0 replacing bundled version of node-pre-gyp with node-pre-gyp@0.6.32

出来た.

$ node
> require( 'opencv' )
{ version: '2.4',
  readImage: [Function: readImage],
  Point: [Function: Point],
  Matrix: 
   { [Function: Matrix]
     Zeros: [Function: Zeros],
     Ones: [Function: Ones],
     Eye: [Function: Eye],
     getRotationMatrix2D: [Function: getRotationMatrix2D] },
  CascadeClassifier: [Function: CascadeClassifier],
  VideoCapture: [Function: VideoCapture],
  Contours: [Function: Contours],
  TrackedObject: [Function: TrackedObject],
  NamedWindow: [Function: NamedWindow],
  ...
  FACE_CASCADE: '/Users/calmery/projects/opencv/node_modules/opencv/data/haarcascade_frontalface_alt.xml',
  EYE_CASCADE: '/Users/calmery/projects/opencv/node_modules/opencv/data/haarcascade_eye.xml',
  EYEGLASSES_CASCADE: '/Users/calmery/projects/opencv/node_modules/opencv/data/haarcascade_eye_tree_eyeglasses.xml',
  FULLBODY_CASCADE: '/Users/calmery/projects/opencv/node_modules/opencv/data/haarcascade_fullbody.xml',
  CAR_SIDE_CASCADE: '/Users/calmery/projects/opencv/node_modules/opencv/data/hogcascade_cars_sideview.xml' }