いつかエンジニアになりたい

Nothing is too late to start

「npm install」がエラー「pyenv: python2: command not found」で失敗する

概要

  • npm install 時に python2 周りのエラーが発生してインストールが失敗する
  • pyenv利用環境下で「python2」コマンドが利用できないのが原因

環境

  • macOS Sierra version 10.12.2
  • npm version 4.0.5
  • node version 7.4.0
  • pyenv version 1.0.6

問題

  • npm install 時に以下のエラーがでてインストールが失敗 -「pyenv: python2: command not found」からpython2コマンドがない
➜  dasher git:(master) npm install

> socketwatcher@0.3.0 install /Users/daicho/work/dasher/node_modules/socketwatcher
> node-gyp rebuild

gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /Users/daicho/.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.13
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 16.3.0
gyp ERR! command "/Users/daicho/.nodebrew/node/v7.4.0/bin/node" "/Users/daicho/.nodebrew/node/v7.4.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/daicho/work/dasher/node_modules/socketwatcher
gyp ERR! node -v v7.4.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
npm ERR! Darwin 16.3.0
npm ERR! argv "/Users/daicho/.nodebrew/node/v7.4.0/bin/node" "/Users/daicho/.nodebrew/current/bin/npm" "install"
npm ERR! node v7.4.0
npm ERR! npm  v4.0.5
npm ERR! code ELIFECYCLE

npm ERR! socketwatcher@0.3.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the socketwatcher@0.3.0 install script 'node-gyp rebuild'.
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 socketwatcher package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs socketwatcher
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls socketwatcher
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/daicho/work/dasher/npm-debug.log

原因

  •  pyenvでpython2コマンドを利用できるように設定できておらず、インストール時に利用するpython2コマンドが見つからなかったため
➜  ~ python2 -V
pyenv: python2: command not found

The `python2' command exists in these Python versions:
  2.7.13

解決策

  • python3しかglobalに設定していなかったため、python2もglobalに設定する
  • 以下の記事の通り、pyenvではpython2.x、3.xの両方を設定できる
  • 自分の環境で実施した結果は以下になる
➜  ~ python2 -V
pyenv: python2: command not found

The `python2' command exists in these Python versions:
  2.7.13
➜  ~ pyenv versions  
  system
  2.7.13
* 3.6.0 (set by /Users/daicho/.pyenv/version
➜  ~ pyenv global 3.6.0 2.7.13
➜  ~ pyenv rehash  
➜  ~ python -V
Python 3.6.0
➜  ~ python2 -V
Python 2.7.13
➜  ~ python3 -V
Python 3.6.0
➜  dasher git:(master) npm install

> socketwatcher@0.3.0 install /Users/daicho/work/dasher/node_modules/socketwatcher
> node-gyp rebuild

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

  CXX(target) Release/obj.target/socketwatcher/socket_watcher.o
../socket_watcher.cpp:104:37: warning: 'NewInstance' is deprecated [-Wdeprecated-declarations]
    info.GetReturnValue().Set(cons->NewInstance());
                                    ^
/Users/daicho/.node-gyp/7.4.0/include/node/v8.h:3292:52: note: 'NewInstance' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
                                                   ^
1 warning generated.
  SOLINK_MODULE(target) Release/socketwatcher.node

> pcap@2.0.0 install /Users/daicho/work/dasher/node_modules/pcap
> node-gyp rebuild

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

  CXX(target) Release/obj.target/pcap_binding/pcap_binding.o
  CXX(target) Release/obj.target/pcap_binding/pcap_session.o
../pcap_session.cc:46:37: warning: 'NewInstance' is deprecated [-Wdeprecated-declarations]
    info.GetReturnValue().Set(cons->NewInstance());
                                    ^
/Users/daicho/.node-gyp/7.4.0/include/node/v8.h:3292:52: note: 'NewInstance' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
                                                   ^
1 warning generated.
  SOLINK_MODULE(target) Release/pcap_binding.node
dasher@1.1.1 /Users/daicho/work/dasher
└─┬ node-dash-button@0.6.1 
  └─┬ pcap@2.0.0  (git+https://github.com/mranney/node_pcap.git#d920204745c8b00ef4b7a3fe27d902b263cdb70f)
    └── socketwatcher@0.3.0 

参考

shinespark.hatenablog.com