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

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

npm install --global windows-build-tools


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.