67

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
Revircs
  • 1,312
  • 3
  • 12
  • 23

6 Answers6

52

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

npm install --global windows-build-tools

Rob
  • 89
  • 1
  • 1
  • 8
Kalpesh Kashyap
  • 824
  • 11
  • 18
  • 1
    This seems to have worked! Thank you, I would have never found this! – Revircs Jan 06 '19 at 08:18
  • 17
    Seems like it wanted Python 2.7 not 3.6. – Liam Mitchell Mar 22 '19 at 02:26
  • 7
    Encountered the same problem, however my system hangs during the visual studio build tools installation(frozen on successfully installed python 2.7 - will it install anything else? it doesn't return me to command prompt). Typed python on command prompt and not working, where should I look for it? – Kieran F. Apr 02 '19 at 04:41
  • I also need to set the python executable path in the environment path in windows. – Ashutosh Chamoli May 07 '19 at 12:22
  • 2
    @KieranF. In my answer below, i showed how to install build tools with python path and also stated where the python executable file can be found after installing it. – Israel Obanijesu May 26 '19 at 14:58
  • Please note: The version of Python is important. Needs to be 2.7 – soupy1976 Sep 05 '19 at 08:31
  • There's also the solution from this [GitHub comment](https://github.com/felixrieseberg/windows-build-tools/issues/152#issuecomment-443785591). You need to install windows-build-tools version 4.0.0. – Paul Razvan Berg Aug 01 '20 at 08:38
  • This will not work with nodejs 18 - you are supposed to install the build tools via the nodejs gui installer now – Anton Duzenko May 12 '23 at 08:38
25

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
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

Hope this solves your problem.

Israel Obanijesu
  • 666
  • 1
  • 12
  • 24
  • `npm --add-python-to-path='true' install --global --production windows-build-tools` solved my issue. thanks! – Mücahit Yılmaz Aug 05 '19 at 10:37
  • 2
    the link to the manual install for the Windows_Build_tools currently returns 404 Not Found. The second tip is recommended, maybe make this the first tip (2nd tip worked for me)? – anneb Nov 10 '19 at 12:43
  • Okay, thank you for letting me know. I've updated the link to where you can download Microsoft Build Tools. Also, the second tip is the recommended one, so that is what i expect people to try out first. – Israel Obanijesu Nov 10 '19 at 22:31
  • After installing Windows Build Tools from the link, open Visual Studio Installer to check if the installation completed successfully. In my case there was a message saying "Installation finished with warnings". To fix this just press the "Update" button. – eddex Dec 13 '19 at 09:44
  • The first one (installing Python 2.7 and pointing npm to it) fixed it for me. Why do we still need Python 2.7 in 2022 for a currently-supported tool like npm... it's kind of ridiculous. – ke4ukz Apr 28 '22 at 16:33
4

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.

Konstantin Lyakh
  • 781
  • 6
  • 15
  • windows build tools readme says windows build tools comes with the recent versions of npm. I found it in my system and just had to add it to the path as @mdowes has said – msanjay Dec 02 '21 at 07:19
4

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

mdowes
  • 592
  • 7
  • 18
3

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.

Vinayk93
  • 353
  • 1
  • 6
1

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.

Kieran F.
  • 567
  • 4
  • 16