所以我从昨天起就开始研究这个问题了,而且似乎无处可去。我曾尝试过关注文档和各种教程,但似乎都没有。
如果我使用默认使用代码的新Javascript文件创建一个新文件夹:
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(':memory:');
db.serialize(function() {
db.run("CREATE TABLE lorem (info TEXT)");
var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
for (var i = 0; i < 10; i++) {
stmt.run("Ipsum " + i);
}
stmt.finalize();
db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
console.log(row.id + ": " + row.info);
});
});
db.close();
然后通过键入node.js CMD来尝试通过npm安装sqlite3:
cd C:\Users\User\Desktop\Sqlite3test
npm install sqlite3
我已收到此错误消息:
C:\Users\User\Desktop\Sqlite3test>npm install sqlite3
\
> sqlite3@3.1.0 install C:\Users\User\node_modules\sqlite3
> node-pre-gyp install --fallback-to-build
C:\Users\User\node_modules\sqlite3>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" clean ) else (node clean )
C:\Users\User\node_modules\sqlite3>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" configure --fallback-to-build --module=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64\node_sqlite3.node --module_name=node_sqlite3 --module_path=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64 --python=c:\Python27\python.exe ) else (node configure --fallback-to-build --module=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64\node_sqlite3.node --module_name=node_sqlite3 --module_path=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64 --python=c:\Python27\python.exe )
C:\Users\User\node_modules\sqlite3>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" build --fallback-to-build --module=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64\node_sqlite3.node --module_name=node_sqlite3 --module_path=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64 ) else (node build --fallback-to-build --module=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64\node_sqlite3.node --module_name=node_sqlite3 --module_path=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64 )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
unpack_sqlite_dep
'python' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targ
ets(170,5): error MSB6006: "cmd.exe" exited with code 1. [C:\Users\User\node_mo
dules\sqlite3\build\deps\action_before_build.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:270:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Windows_NT 10.0.10240
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "build" "--fallback-to-build" "--module=C:\\Users\\User\\node_modules\\sqlite3\\lib\\binding\\node-v46-win32-x64\\node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=C:\\Users\\User\\node_modules\\sqlite3\\lib\\binding\\node-v46-win32-x64"
gyp ERR! cwd C:\Users\User\node_modules\sqlite3
gyp ERR! node -v v4.0.0
gyp ERR! node-gyp -v v3.0.1
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'node-gyp.cmd build --fallback-to-build --module=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64\node_sqlite3.node --module_name=node_sqlite3 --module_path=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64' (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (C:\Users\User\node_modules\sqlite3\node_modules\node-pre-gyp\lib\util\compile.js:83:29)
node-pre-gyp ERR! stack at emitTwo (events.js:87:13)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:172:7)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:817:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
node-pre-gyp ERR! System Windows_NT 10.0.10240
node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\User\\node_modules\\sqlite3\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd C:\Users\User\node_modules\sqlite3
node-pre-gyp ERR! node -v v4.0.0
node-pre-gyp ERR! node-pre-gyp -v v0.6.10
node-pre-gyp ERR! not ok
Failed to execute 'node-gyp.cmd build --fallback-to-build --module=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64\node_sqlite3.node --module_name=node_sqlite3 --module_path=C:\Users\User\node_modules\sqlite3\lib\binding\node-v46-win32-x64' (1)
npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "sqlite3"
npm ERR! node v4.0.0
npm ERR! npm v2.14.2
npm ERR! code ELIFECYCLE
npm ERR! sqlite3@3.1.0 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sqlite3@3.1.0 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! This is most likely a problem with the sqlite3 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-pre-gyp install --fallback-to-build
npm ERR! You can get their info via:
npm ERR! npm owner ls sqlite3
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\User\Desktop\Sqlite3test\npm-debug.log
进一步了解NPM website关于sqlite3的文档,它说我必须见到&#34; node-gyp's requirements&#34;。我已经完成了所有这些。如果我事先使用:
设置python环境npm config set python C:\Python27\python.exe
我收到相同的错误消息。我不知道发生了什么。可能是因为Windows 10目前不支持node-gyp要求吗?
答案 0 :(得分:0)
由于您使用的是Windows,请尝试
set PYTHON=python2.7
答案 1 :(得分:0)
好的,所以我找到了解决方案。
事实证明我的Python环境变量未正确设置。我在另一个帖子上查了一下,发现Delicia Brummitt发布了这个解决方案: