Skip to content Skip to sidebar Skip to footer

Node.js (npm) Refuses To Find Python Even After %python% Has Been Set

So I am trying to get the Node.js to work. Of course, it's not as easy as advertised :) I happen to have two python versions on my computer, but Node.js seems to only work with the

Solution 1:

I figured out the most stable solution is to set python npm internal value to actual path:

npm config set python C:\Programs\Python2.7\python2.7.exe

This skips all environment variable and %PATH% crap and just starts the python wherever it's installed.

Solution 2:

TL;DR Make a copy or alias of your python.exe with name python2.7.exe

My python 2.7 was installed as

D:\app\Python27\python.exe

I always got this error no matter how I set (and verified) PYTHON env variable:

gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
gyp ERR! stack     at failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:103:14)

The reason for this was that in node-gyp's configure.js the python executable was resolved like:

var python = gyp.opts.python || process.env.PYTHON || 'python'

And it turned out that gyp.opts.python had value 'python2.7' thus overriding process.env.PYTHON.

I resolved this by creating an alias for python.exe executable with name node-gyp was looking for:

D:\app\Python27>mklink python2.7.exe python.exe

You need admin rights for this operation.

Solution 3:

Reopen your terminal after you set your environment variable in case of windows but in case of linux no need to restart terminal.

Solution 4:

This worked for me:

npm config set python C:\Users\<username>\.windows-build-tools\python27\python.exe

Set the path to python executable accordingly. Hope this help :-)

Solution 5:

On Windows goto directory C:\Users\<<your username>>\.windows-build-tools\python27 and copy and paste the python.exe as python.2.7.exe in the same directory.

Post a Comment for "Node.js (npm) Refuses To Find Python Even After %python% Has Been Set"