Thursday, 13 September 2018

node-gyp and Python support on Windows

node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js. [node-gyp on GitHub] [node-gyp]

If you try to run node-gyp on a machine with no Python installed you might get an error similar to this:

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\user\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack at PythonFinder. (C:\Users\user\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack at C:\Users\user\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:158:21)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\user\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\whatever\my-app\node_modules\dtrace-provider
gyp ERR! node -v v10.7.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

(cwd in this output message stands for Current Working Directory)

If you have Python 3 installed, the same command will fail for Python 3 interpreter not be able to parse Python 2 code...This happens as node-gyp (still) doesn't support Python 3 so you'll need to install Python 2 (2.7.x).

When installing Python 2 DO NOT opt for adding its path to PATH environment variable as otherwise it will make Python 2 the default one on the machine.

The easiest way to make node-gyp working with Python 2 while not interfering with existing Python 3 paths is to follow the suggestion from the error message above, create PYTHON env variable and set its value to Python 2 path (C:\Python27). Then we can have this setup before we execute node node-gyp.js:

>python --version
Python 3.7.0

>echo %PYTHON%
C:\Python27


1 comment:

micheal pan said...

BE SMART AND BECOME RICH IN LESS THAN 3DAYS....It all depends on how fast 
you can be to get the new PROGRAMMED blank ATM card that is capable of
hacking into any ATM machine,anywhere in the world. I got to know about 
this BLANK ATM CARD when I was searching for job online about a month 
ago..It has really changed my life for good and now I can say I'm rich and 
I can never be poor again. The least money I get in a day with it is about 
$50,000.(fifty thousand USD) Every now and then I keeping pumping money 
into my account. Though is illegal,there is no risk of being caught 
,because it has been programmed in such a way that it is not traceable,it 
also has a technique that makes it impossible for the CCTVs to detect 
you..For details on how to get yours today, email the hackers on : (
atmmachinehackers1@gmail.com ). Tell your 
loved once too, and start to live large. That's the simple testimony of how 
my life changed for good...Love you all ...the email address again is ;
atmmachinehackers1@gmail.com