Npm and Gyp errors during Apm install

Apm ran into a long list of gyp and npm errors during install all of a sudden and I am lost as to how to fix it. Updating packages, however, seem to be working fine.

Installing atom-keyboard-macros to /Users/satibodhi/.atom/packages ✗

> keyboard-layout@2.0.13 install /private/var/folders/rw/rpr418x91h13ysbc6k7fzj240000gn/T/apm-install-dir-118328-1027-kuvdu3.3i3apmbo6r/node_modules/atom-keyboard-macros/node_modules/keyboard-layout
> node-gyp rebuild

└── (empty)

npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
gyp ERR! configure error 
gyp ERR! stack Error: Python executable "/Applications/" is v3.6.5, 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 (/Applications/
gyp ERR! stack     at /Applications/
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:197:7)
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:877:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
gyp ERR! System Darwin 17.2.0
gyp ERR! command "/Applications/" "/Applications/" "rebuild"
gyp ERR! cwd /private/var/folders/rw/rpr418x91h13ysbc6k7fzj240000gn/T/apm-install-dir-118328-1027-kuvdu3.3i3apmbo6r/node_modules/atom-keyboard-macros/node_modules/keyboard-layout
gyp ERR! node -v v6.9.5
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
npm WARN enoent ENOENT: no such file or directory, open '/private/var/folders/rw/rpr418x91h13ysbc6k7fzj240000gn/T/apm-install-dir-118328-1027-kuvdu3.3i3apmbo6r/package.json'
npm WARN apm-install-dir-118328-1027-kuvdu3.3i3apmbo6r No description
npm WARN apm-install-dir-118328-1027-kuvdu3.3i3apmbo6r No repository field.
npm WARN apm-install-dir-118328-1027-kuvdu3.3i3apmbo6r No README data
npm WARN apm-install-dir-118328-1027-kuvdu3.3i3apmbo6r No license field.
npm ERR! Darwin 17.2.0
npm ERR! argv "/Applications/" "/Applications/" "--globalconfig" "/Users/satibodhi/.atom/.apm/.apmrc" "--userconfig" "/Users/satibodhi/.atom/.apmrc" "install" "/private/var/folders/rw/rpr418x91h13ysbc6k7fzj240000gn/T/d-118328-1027-1ncxuoz.zkdmrkke29/package.tgz" "--runtime=electron" "--target=1.7.11" "--arch=x64" "--global-style"
npm ERR! node v6.9.5
npm ERR! npm  v3.10.10

npm ERR! keyboard-layout@2.0.13 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the keyboard-layout@2.0.13 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 keyboard-layout 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 keyboard-layout
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls keyboard-layout
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /private/var/folders/rw/rpr418x91h13ysbc6k7fzj240000gn/T/apm-install-dir-118328-1027-kuvdu3.3i3apmbo6r/npm-debug.log
npm ERR! code 1 

Any ideas?

gyp ERR! stack Error: Python executable “/Applications/” is v3.6.5, 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.
Hmm, that looks like the issue? Did you use Homebrew to install Python?

Yes, I have both python 2.7 and 3 installed via homebrew.

I’ve recently aliased ‘python’ to python3 through the ~/.bash_alias file.

Node-gyp is incompatible with Python 3.
Don’t ask me why it can’t just use the right Python version.
I really don’t know.
It even says how to do it in the error message.

How do I get apm to pass the required python switch to npm without amending my batch alias?

npm config set python python2.7 doesn’t seem to work.

No idea. I just remove Python stuff from my path while using node-gyp (which is thankfully rare something I need to do when developing tree-sitter grammars).

The issue was resolved by removing export PATH="/usr/local/opt/python/libexec/bin:$PATH" from my ~/.bash_profile and setting npm config set python python2.7.
Apparently, there’s been a couple conflicting locations where python can be accessed on a Mac.
The default from Homebrew installations should be /usr/local/bin.

ls -la | grep python shows the list of python installations available on that path, which includes both python 2 and 3:

lrwxr-xr-x    1 satibodhi  admin       39  4 11 08:43 python2 -> ../Cellar/python@2/2.7.14_3/bin/python2
lrwxr-xr-x    1 satibodhi  admin       46  4 11 08:43 python2-config -> ../Cellar/python@2/2.7.14_3/bin/python2-config
lrwxr-xr-x    1 satibodhi  admin       41  4 11 08:43 python2.7 -> ../Cellar/python@2/2.7.14_3/bin/python2.7
lrwxr-xr-x    1 satibodhi  admin       48  4 11 08:43 python2.7-config -> ../Cellar/python@2/2.7.14_3/bin/python2.7-config
lrwxr-xr-x    1 satibodhi  admin       34  4  4 11:39 python3 -> ../Cellar/python/3.6.5/bin/python3
lrwxr-xr-x    1 satibodhi  admin       41  4  4 11:39 python3-config -> ../Cellar/python/3.6.5/bin/python3-config
lrwxr-xr-x    1 satibodhi  admin       36  4  4 11:39 python3.6 -> ../Cellar/python/3.6.5/bin/python3.6
lrwxr-xr-x    1 satibodhi  admin       43  4  4 11:39 python3.6-config -> ../Cellar/python/3.6.5/bin/python3.6-config
lrwxr-xr-x    1 satibodhi  admin       37  4  4 11:39 python3.6m -> ../Cellar/python/3.6.5/bin/python3.6m
lrwxr-xr-x    1 satibodhi  admin       44  4  4 11:39 python3.6m-config -> ../Cellar/python/3.6.5/bin/python3.6m-config

/usr/local/opt/python/libexec/bin, however, only contains python3, as can be seen from the result of ls -la | grep python on the directory below:

lrwxr-xr-x  1 satibodhi  admin   60  4  4 11:39 python -> ../../Frameworks/Python.framework/Versions/3.6/bin/python3.6
lrwxr-xr-x  1 satibodhi  admin   68  4  4 11:39 python-config -> ../../Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config

I think npm was searching for python2.7 in the wrong place, which is what gave rise to the error.