こんなエラーが出た時のお話。
~ $ npm install -g bower /Users/<user_name>/.nvm/versions/node/v4.2.1/bin/bower -> /Users/<user_name>/.nvm/versions/node/v4.2.1/lib/node_modules/bow er/bin/bower bower@1.6.5 /Users/<user_name>/.nvm/versions/node/v4.2.1/lib/node_modules/bower > bufferutil@1.2.1 install /Users/<user_name>/.nvm/versions/node/v4.2.1/lib/node_modules/browser-sync/node_modules/sock et.io/node_modules/engine.io/node_modules/ws/node_modules/bufferutil > node-gyp rebuild gyp ERR! configure error gyp ERR! stack Error: Command failed: 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.6 gyp ERR! stack gyp ERR! stack gyp ERR! stack at ChildProcess.exithandler (child_process.js:203:12) gyp ERR! stack at emitTwo (events.js:87:13) gyp ERR! stack at ChildProcess.emit (events.js:172:7) gyp ERR! stack at maybeClose (internal/child_process.js:818:16) gyp ERR! stack at Socket.<anonymous> (internal/child_process.js:319:11) gyp ERR! stack at emitOne (events.js:77:13) gyp ERR! stack at Socket.emit (events.js:169:7) gyp ERR! stack at Pipe._onclose (net.js:469:12)
原因
npm install ではSystemで動作するPython 2系を想定しているのに、pyenvで3系をglobalに指定していたのが原因だった。
python3はpathが通っているけれど、python2はPathが通っていない状態。これをなんとかしたい。
pyenv見直し前
global に 3.5.0 のみ指定していた
$ pyenv global 3.5.0
pyenv見直し後
global に 2.7.6 と 3.5.0を指定するようにした
$ pyenv global 2.7.6 3.5.0 $ pyenv global 2.7.6 3.5.0
ちなみにこれで python2
, python3
コマンドで各verの指定が可能に。
$ python Python 2.7.6 (default, Oct 22 2015, 19:45:06) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> $ python2 Python 2.7.6 (default, Oct 22 2015, 19:45:06) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> $ python3 Python 3.5.0 (default, Sep 18 2015, 02:24:52) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
この状態で npm install -g すると無事に実行できた。
追記: 2017/12/26
昨今では pyenv の利用自体辞めた方がよいと言われている。