npm install fail when PATH contains a path to Python3

What I Wanted to Do

npm install

What Happened Instead

It fails with this error:

gyp ERR! stack Error: Command failed: D:\Program Files (x86)\Python\python.exe -c import sys; print “%s.%s.%s” % sys.version_info[:3];
gyp ERR! stack File “”, line 1
gyp ERR! stack import sys; print “%s.%s.%s” % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax

Reproduction Steps

Install Python 3 and add the path into the PATH environment variable.
add node-sass (v 4.9.3 in my case) to package.json
“node-sass”: “^4.9.3”,

Details

I think that when package.json contains node-sass it will fail if the Windows PATH variable contain the path to Python 3.
It is trying to use the old version of the print command (Python 2).

Please don’t say that I should have Python 2. It is probably more than 10 years that I migrated to Python 3.

Full script result:

D:\Data\GIT\SS.Betting.Tools\Web App 7\Web App 7\ClientApp>npm install

node-sass@4.9.3 install D:\Data\GIT\SS.Betting.Tools\Web App 7\Web App 7\ClientApp\node_modules\node-sass
node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.9.3/win32-x64-72_binding.node
Cannot download “https://github.com/sass/node-sass/releases/download/v4.9.3/win32-x64-72_binding.node”:

HTTP error 404 Not Found

Hint: If github.com is not accessible in your location
try setting a proxy via HTTP_PROXY, e.g.

  export HTTP_PROXY=http://example.com:1234

or configure npm proxy via

  npm config set proxy http://example.com:8080

node-sass@4.9.3 postinstall D:\Data\GIT\SS.Betting.Tools\Web App 7\Web App 7\ClientApp\node_modules\node-sass
node scripts/build.js

Building: D:\Program Files\nodejs\node.exe D:\Data\GIT\SS.Betting.Tools\Web App 7\Web App 7\ClientApp\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli ‘D:\Program Files\nodejs\node.exe’,
gyp verb cli ‘D:\Data\GIT\SS.Betting.Tools\Web App 7\Web App 7\ClientApp\node_modules\node-gyp\bin\node-gyp.js’,
gyp verb cli ‘rebuild’,
gyp verb cli ‘–verbose’,
gyp verb cli ‘–libsass_ext=’,
gyp verb cli ‘–libsass_cflags=’,
gyp verb cli ‘–libsass_ldflags=’,
gyp verb cli ‘–libsass_library=’
gyp verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@12.10.0 | win32 | x64
gyp verb command rebuild
gyp verb command clean
gyp verb clean removing “build” directory
gyp verb command configure
gyp verb check python checking for Python executable “D:\Program Files (x86)\Python\python.exe” in the PATH
gyp verb which succeeded D:\Program Files (x86)\Python\python.exe D:\Program Files (x86)\Python\python.exe
gyp ERR! configure error
gyp ERR! stack Error: Command failed: D:\Program Files (x86)\Python\python.exe -c import sys; print “%s.%s.%s” % sys.version_info[:3];
gyp ERR! stack File “”, line 1
gyp ERR! stack import sys; print “%s.%s.%s” % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:295:12)
gyp ERR! stack at ChildProcess.emit (events.js:209:13)
gyp ERR! stack at maybeClose (internal/child_process.js:1021:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command “D:\Program Files\nodejs\node.exe” “D:\Data\GIT\SS.Betting.Tools\Web App 7\Web App 7\ClientApp\node_modules\node-gyp\bin\node-gyp.js” “rebuild” “–verbose” “–libsass_ext=” “–libsass_cflags=” “–libsass_ldflags=” “–libsass_library=”
gyp ERR! cwd D:\Data\GIT\SS.Betting.Tools\Web App 7\Web App 7\ClientApp\node_modules\node-sass
gyp ERR! node -v v12.10.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

Platform Info

npm --versions 6.10.3 node -p process.platform
win32

Windows 10 64bit
Python 3 installed in D:\Program Files (x86)\Python and registered in PATH

The node-gyp homepage has some instructions for setup and configuring python version :

Thanks for the links.
Unfortunately, installing Python 2 nowdays, just to run a new project in Angular 8, is not an option for me (my team).
I decided to not use SASS but LESS or plain CSS for this project.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.