How to fix electron sqlite3 rebuild error ( Syntax error) on windows 10

…衆ロ難τιáo~ 提交于 2020-01-25 11:25:25

问题


So I ran npm install --global windows-build-tools thing as an administrator and it said that I have successfully installed python 2.7.

But then when I tried electron-rebuild -f -w sqlite3 after npm i sqlite3 it gives me this error.

× Rebuild Failed

An unhandled error occurred inside electron-rebuild

gyp ERR! configure error

gyp ERR! stack Error: Command failed: C:\Users\newub\AppData\Local\Programs\Python\Python37\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


回答1:


It shows node-gyp is using python 3 in your system.

But node-gyp needs python 2.

You can add python 2 Path in your $Path environment variable before python 3 Path.

type which python in cmd make sure it's python 2.




回答2:


According to the message you are using Python 3.7 but those code need Python 2.7 to run.

You can identify which Python version node-gyp should use in one of the following ways:

  1. If node-gyp is called by way of npm, and you have multiple versions of Python installed, then you can set npm's 'python' config key to the appropriate value:

$ npm config set python /path/to/executable/python 
  1. If the PYTHON environment variable is set to the path of a Python executable, then that version will be used, if it is a compatible version.

  2. If the NODE_GYP_FORCE_PYTHON environment variable is set to the path of a Python executable, it will be used instead of any of the other configured or builtin Python search paths. If it's not a compatible version, no further searching will be done.

You can use set command in cmd dispaly environment variable.

PS: Using node-gyp in Windows needs Visual C++ build tools, Python 2.7 (v3.x.x is not supported) and some config. You can

Install all the required tools and configurations using Microsoft's windows-build-tools by running npm install -g windows-build-tools from an elevated PowerShell (run as Administrator).

See:

set python version: nodejs/node-gyp: Node.js native addon build tool

Environment setup and configuration: nodejs-guidelines/windows-environment.md at master · microsoft/nodejs-guidelines



来源:https://stackoverflow.com/questions/53531718/how-to-fix-electron-sqlite3-rebuild-error-syntax-error-on-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!