问题
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:
- If
node-gyp
is called by way ofnpm
, and you have multiple versions of Python installed, then you can setnpm
's 'python' config key to the appropriate value:$ npm config set python /path/to/executable/python
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.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