LoginSignup
11
12

More than 5 years have passed since last update.

npm installとapm rebuildがpythonのバージョン違いでこけた時の対処

Last updated at Posted at 2017-03-19

Atomのパッケージに不具合があったのでrebuildしようと思ってnpm installapm rebuildしたところ、エラーでこけたのでその時の対処方法を忘れないうちにメモ
(環境はmacOS Sierraです)

やろうとしたこと: http://namedpython.hatenablog.com/entry/2017/01/01/192739

①npm installエラー

npm installでこんなのが出ました

コンソール
$ npm install

> pty.js@0.3.1 install /Users/lanocci/.atom/packages/terminal-plus/node_modules/pty.js
> node-gyp rebuild

gyp ERR! configure error 
gyp ERR! stack Error: Python executable "/Users/lanocci/.pyenv/shims/python" is v3.5.2, which is not supported by gyp.
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.
gyp ERR! stack     at PythonFinder.failPythonVersion (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:463:19)
gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:445:14)
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:201:7)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:194:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:899:16)
gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:342:11)
gyp ERR! stack     at emitOne (events.js:96:13)
gyp ERR! stack     at Socket.emit (events.js:191:7)
gyp ERR! stack     at Pipe._handle.close [as _onclose] (net.js:513:12)
...

pythonのバージョンがサポートされてないよってことですね

①の対処

コマンド
$ npm install --python=python2.7

もしくは

$ npm config set python python2.7
$ npm install

node-gypというプラットフォームのネイティブ機能を利用するためのnpmを扱う時にpythonが呼ばれ、それがpython2系でしか動作しないみたい。
以前軽いノリでデフォルトのpythonを3系にしちゃったために起きたエラーですね。
python2.7の部分はpython2.5以上3未満ならOKみたいです。

参考: http://stackoverflow.com/questions/20454199/how-to-use-a-different-version-of-python-during-npm-install

②apm rebuild エラー

①の教訓を生かしてpythonバージョン指定してapm rebuildしても上手くいかない

コンソール
$ apm rebuild --python=python2.7

Rebuilding modules ✗
gyp ERR! configure error 
gyp ERR! stack Error: Python executable "/private/var/folders/nj/_20lj1x931s05z_p2zh4_6p40000gn/T/AppTranslocation/C3646CFC-7538-4A41-A0DE-C3F9EC953732/d/Atom.app/Contents/Resources/app/apm/bin/python-interceptor.sh" is v3.5.2, which is not supported by gyp.
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.
gyp ERR! stack     at failPythonVersion (/private/var/folders/nj/_20lj1x931s05z_p2zh4_6p40000gn/T/AppTranslocation/C3646CFC-7538-4A41-A0DE-C3F9EC953732/d/Atom.app/Contents/Resources/app/apm/node_modules/node-gyp/lib/configure.js:454:14)
gyp ERR! stack     at /private/var/folders/nj/_20lj1x931s05z_p2zh4_6p40000gn/T/AppTranslocation/C3646CFC-7538-4A41-A0DE-C3F9EC953732/d/Atom.app/Contents/Resources/app/apm/node_modules/node-gyp/lib/configure.js:443:9
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:204:7)
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:827: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:477:12)

...

②の対処

apmは実行時に.apmrcファイルを読みに行くので、以下のコマンドで.apmrcファイルを編集してあげると上手くいく

コマンド
echo "python=python2.7" >> ~/.atom/.apmrc
apm rebuild

こっちもpython2.7の部分はpython2.5以上3未満ならOKみたいです。

参考: https://github.com/atom/apm/issues/179

EmacsからAtomへの乗り換え頑張りまーす

11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12