0

我在为 Node.js 安装 Postgres 数据库模块时遇到问题,每次运行命令“npm install pg”时都会出现以下错误:
C:>npm install pg
npm http GET https://registry.npmjs.org/pg
npm http 200 https://registry.npmjs.org/pg
npm http GET https://registry.npmjs.org/pg/-/pg-0.12.1.tgz
npm http 200 https://registry.npmjs.org/pg/-/pg-0.12.1.tgz
npm http GET https://registry.npmjs.org/generic-pool/2.0.2
npm http 200 https://registry.npmjs.org/generic-pool/2.0.2
npm http GET https://registry.npmjs.org/generic-pool/-/generic-pool-2.0.2.tgz
npm http 200 https://registry.npmjs.org/generic-pool/-/generic-pool-2.0.2.tgz

pg@0.12.1 install C:\node_modules\pg
node-gyp rebuild || (exit 0)

C:\node_modules\pg>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-b
in\....\node_modules\node-gyp\bin\node-gyp.js" rebuild
'pg_config' is not recognized as an internal or external command,
operable program or batch file.
gyp: Call to 'pg_config --libdir' returned exit status 1. while trying to load b
inding.gyp
gyp ERR! configure error
gyp ERR! stack Error: gyp failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\Program Files\nodejs\node_module
s\npm\node_modules\node-gyp\lib\configure.js:420:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:99:17)
gyp ERR! stack at Process._handle.onexit (child_process.js:678:10)
gyp ERR! System Windows_NT 5.1.2600
gyp ERR! command "node" "C:\Program Files\nodejs\node_modules\npm\node_modu
les\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\node_modules\pg
gyp ERR! node -v v0.8.17
gyp ERR! node-gyp -v v0.8.2
gyp ERR! not ok
pg@0.12.1 node_modules\pg
└── generic-pool@2.0.2

这个错误发生在我的工作机器(linux/windows box)和我家的个人机器(windows)上。有任何想法吗?

另外我应该提到我已经安装了 Python 2.7.3。

4

3 回答 3

5

您在 Windows 上:

'pg_config' is not recognized as an internal or external command, operable program or batch file.

所以我建议您获取 pg 模块的预构建二进制文件。在 Windows 上编译东西……很有趣。

直接的错误是pg_config可执行文件不在 . PATH,但是在你修复它之后会有更多。除非您计划进行探索和宣誓之旅,否则获取预构建的可执行文件。

于 2013-01-29T07:47:05.450 回答
1

安装 postgres db ( https://www.postgresql.org/download/ ) 并确保其 bin 文件夹路径存在于环境变量中

在此处输入图像描述

于 2020-08-18T10:24:44.030 回答
0

在 PATH 变量中指定 Postgres bin 文件夹,然后不要忘记以管理员权限重新启动 cmd.exe

于 2017-04-11T22:05:17.910 回答