Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python.exe Syntax issue - NPM

I am having trouble when running Npm install. I get the following error:

gyp ERR! stack Error: Command failed: C:\Users\userxxx\AppData\Local\Programs\Python\Python37-32\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", 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:276:12)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:915:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"

I have added to my Path system variable the following:

C:\Python27\

In my user Path variable I have the following for Python:

C:\Users\userxxx\AppData\Local\Programs\Python\Python37-32\Scripts\
C:\Users\userxxx\AppData\Local\Programs\Python\Python37-32\
C:\Users\userxxx\AppData\Local\Programs\Python\Python37\Scripts\
C:\Users\userxxx\AppData\Local\Programs\Python\Python37\

Not sure what is going on here so any help appreciated!

like image 463
M guy Avatar asked Nov 16 '18 13:11

M guy


People also ask

How do I resolve npm installation issues?

The easiest way to fix the issue is to pass an additional parameter –legacy-peer-deps to npm install. The --legacy-peer-deps tells the npm to ignore the peer dependencies and continue the installation of the package.

Could not find Python npm install?

To Solve Can't find Python executable “python”, you can set the PYTHON env variable Error You just need to Install Python In Your Windows ( If Not Installed ) and then add python to your PATH variable. Using environment variable. OR You can set npm config set python path and it will also Solve your error.

Does npm work with Python?

It is possible to specify a python version when npm installing npm install --python=python2. 7 . We can also configure npm to use a specific version of python (stackoverflow).

Do we need Python for npm install?

NPM has a package called windows-build-tools that should automatically install everything you need to get node-gyp working, including the Microsoft build tools, compilers, Python, and everything else required to build native Node modules on Windows.


2 Answers

The command you are attempting to run uses Python 2 syntax. It is incompatible with Python 3, so if you try to use that, you should get a syntax error.

Either upgrade the script to Python 3 (about time already), or fix the execution path so that it can be run with the obsolescent Python version.

like image 67
tripleee Avatar answered Nov 03 '22 06:11

tripleee


Two solution we can try in this case

  1. Downgrade Python to 2.x.

  2. Install the packages using npm install --ignore-scripts

    NOTE: This will cause npm to stop running scripts defined in the package.json

like image 28
Shiv Kumar Baghel Avatar answered Nov 03 '22 06:11

Shiv Kumar Baghel