}

Windows-Build-Tools: Can't find Python executable "python" after installing

Created:

The problem

Node.js native addon build tool (node-gyp) installation fails since python was not found.

The output of node-gyp installation error should be similar to this one:

+ node_modules/.bin/electron-rebuild --arch x64 -f -p -w serialport -m electron-app
× Rebuild Failed
An unhandled error occurred inside electron-rebuild
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (C:\Users\tutorialstechnology\workspace\app\node_modules\node-gyp\lib\configure.js:482:19)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Users\tutorialstechnology\workspace\app\node_modules\node-gyp\lib\configure.js:508:16)
gyp ERR! stack     at C:\Users\tutorialstechnology\workspace\app\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:114:15)
gyp ERR! System Windows_NT 10.0.15063
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\tutorialstechnology\\workspace\\app\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=1.4.13" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source" "--module_name=serialport" "--module_path=C:\\Users\\tutorialstechnology\\workspace\\app\\electron-app\\node_modules\\serialport\\build\\Release" "--host=https://github.com/EmergingTechnologyAdvisors/node-serialport/releases/download/4.0.7"
gyp ERR! cwd C:\Users\tutorialstechnology\\workspace\\app\\electron-app\node_modules\serialport
gyp ERR! node -v v7.9.0
gyp ERR! node-gyp -v v3.6.0
gyp ERR! not ok

Solution

Install windows-build-tools with --production and --global parameters:

npm install --global --production windows-build-tools

If the error still appears, try to add the --add-python-to-path='true

npm --add-python-to-path='true' --debug install --global windows-build-tools