nwjs / nw-gyp

native addon build tool for node-webkit
MIT License
195 stars 46 forks source link

npm install fails due to using wrong python version when run from batch (yet works when run via command prompt/powershell) #140

Open NbrTDB opened 3 years ago

NbrTDB commented 3 years ago

I have encountered this odd situation trying to use nw-gyp on a Windows 10 system with Python38 and Python27 in the system PATH.

On this system, if I run npm install --msvs_version=2017 via the command prompt/powershell, everything works just fine.

But when it is run via a batch file as part of a build script, the process fails, citing syntax errors that are a clear indicator it's trying to use Python 3 instead of Python 2.

I've tried various things within the batch file to encourage the right python target to be used (not all at the same time, just listing them below) and all of them were ineffectual:

set PYTHON=C:\Python27\python.exe
set npm_config_python=C:\Python27\python.exe
npm config set python C:\Python27\python.exe
npm install --python=python2.7 --msvs_version=2017

It should be noted that I can see Python27 listed in npm config ls -l and npm config get python if used in the batch file will echo the desired Python 2.7 path. At this point I have run out of ideas, it seems like all attempts to declare a target for Python are ignored when npm install is called from batch.

I do have a not-ideal workaround: if I simply shuffle the environment variables around such that Python27 is first, I can use nw-gyp without problem.

This seems rather similar to #122 (certainly, the issue of nw-gyp seemingly ignoring path variables does appear to be the case).