After `npm install` an error about a syntax error in python appears?

Javascriptnode.jsNpm Install

Javascript Problem Overview


I am trying to install the necessary dependencies for Exokit, but I am getting an error relating to a Python syntax error.

This is for a something new I wanted to try involving VR in the browser. I've recloned the repository from their github and downloaded straight from their website. I followed the instructions given to a T (there was only 4 of them lol).

I have not yet touched the code and this is the error that I am getting.

Austin@DESKTOP-UD2R1O4 MINGW64 ~/exokit (master)
$ npm install

> raw-buffer@0.0.19 install C:\Users\Austin\exokit\node_modules\raw-buffer
> node-gyp rebuild


C:\Users\Austin\exokit\node_modules\raw-buffer>if not defined 
npm_config_node_gyp (node "C:\Program 
Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp- 
bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node 
"C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\Austin\Anaconda3\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"
gyp ERR! cwd C:\Users\Austin\exokit\node_modules\raw-buffer
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! raw-buffer@0.0.19 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the raw-buffer@0.0.19 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Austin\AppData\Roaming\npm-cache\_logs\2019-01-06T06_55_37_752Z-debug.log

Javascript Solutions


Solution 1 - Javascript

Try this in cmd administrator (or Windows Powershell Administrator if cmd freezes)

> npm install --global windows-build-tools

Solution 2 - Javascript

In case the answer(s) provided doesn't work for you, here are some tips you can follow in order to mitigate related problems for windows OS.

NOTE: If you already tried installing the build tools via npm command with no success, it is probably a good idea to delete everything before applying any of the tips below.

You can find the build tools here and just delete the folders (but I don't know if they are installed somewhere else):

  • C:\Users\'yourUser'\.windows-build-tools\
  • C:\Users\'yourUser'\AppData\Roaming\npm\node_modules\windows-build-tools

After ensuring that the folders specified above are deleted, then you can try applying any of the following tips.

First Tip:

  • Run CMD or PowerShell as Administrator
  • Install node-gyp using the following command: npm install -g node-gyp
  • Download and install windows build tools manually from this link: Windows_Build_tools
  • Download and install Python 2.7
  • Register Microsoft Visual Studio version to npm using the following command: npm config set msvs_version <your msvs_version e.g. 2017>
  • Register the path of python executable file to npm using the following command: npm config set python <the path to python executable file>

Second Tip (RECOMMENDED)

  • Run CMD or PowerShell as Administrator
  • Install windows-build-tools with the python-path directly using the following command: npm --add-python-to-path='true' install --global --production windows-build-tools
  • You can run the following command: npm config set python <the path to python executable file>, in order to be sure that npm is pointing to the correct path of python executable file.
    In order to use this command, you can find the python path here (i.e. after running the command in the previous step): C:\Users\<your_user_name>\.windows-build-tools\python27

More information or description about node-gyp can be found here: node-gyp

More information about possible windows build tools issues can be found in the following links: https://github.com/felixrieseberg/windows-build-tools/issues/47<br> https://github.com/felixrieseberg/windows-build-tools/issues/56

Additional Note: Some people tend to have spaces in their project path names whereas, some tools don't handle spaces in path names well. You can get more info here: https://github.com/nodejs/node-gyp/issues/809</b>

Hope this solves your problem.

Solution 3 - Javascript

In case you already have newer Python version installed, no need to uninstall it. You can install older Python 2.7 version and follow recommendations in this answer.

Solution 4 - Javascript

Any error that points to a syntax error while executing python code is due to the version of python (python v3 or v2) executable that executes the python script file. In this case specifically, npm is trying to build few node modules because binaries for those modules are not published on internet. Hence when an incorrect version of python compiler (or interpreter as some would say) is loaded and used to build python code, you will see syntax error.

The fix to such problem is not to uninstall python, because you may need both versions of python for different purposes. Simply add python v2 path before python v3 if you have both or if you do not have python then install python v2 and add the location to environment variable as shown below. Hope this solves the issue.

EnvVariables

Solution 5 - Javascript

Node.js is built with GYP — cross-platform built tool written in Python. Also some other build steps are implemented in Python. So Python is required for building node from source.

But you also need Python for building native addons.

Solution 6 - Javascript

I found success by re-installing NPM version 11 and making sure to tick the checkbox when it asks if you'd like to install additional tools (something related to Microsoft visual studio build tools). I was then able to run npm install and then `npm . "http://webvrwebsite.com" successfully.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRevircsView Question on Stackoverflow
Solution 1 - JavascriptKalpesh KashyapView Answer on Stackoverflow
Solution 2 - JavascriptIsrael ObanijesuView Answer on Stackoverflow
Solution 3 - JavascriptKonstantin LyakhView Answer on Stackoverflow
Solution 4 - JavascriptmdowesView Answer on Stackoverflow
Solution 5 - JavascriptVinayk93View Answer on Stackoverflow
Solution 6 - JavascriptKieran F.View Answer on Stackoverflow