在OSX和Ubuntu上npm install odbc失败

Pat*_*ard 1 macos ubuntu node.js

我在OSX和Ubuntu上安装odbc软件包时遇到问题.

我在两台机器上安装了unixODBC.

这是发出"npm install odbc"的输出:

npm http GET https://registry.npmjs.org/odbc
npm http 304 https://registry.npmjs.org/odbc

> odbc@0.6.3 preinstall /home/notes/as400/node_modules/odbc
> node-gyp configure build

Traceback (most recent call last):
  File "/usr/share/node-v0.10.26-linux-x64/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 18, in <module>
    sys.exit(gyp.script_main())
AttributeError: 'module' object has no attribute 'script_main'
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/share/node-v0.10.26-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.11.0-12-generic
gyp ERR! command "node" "/usr/share/node-v0.10.26-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /home/notes/as400/node_modules/odbc
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok 
npm ERR! odbc@0.6.3 preinstall: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the odbc@0.6.3 preinstall script.
npm ERR! This is most likely a problem with the odbc package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp configure build
npm ERR! You can get their info via:
npm ERR!     npm owner ls odbc
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.11.0-12-generic
npm ERR! command "/usr/share/node/bin/node" "/usr/share/node/bin/npm" "install" "odbc"
npm ERR! cwd /home/notes/as400
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/notes/as400/npm-debug.log
npm ERR! not ok code 0
Run Code Online (Sandbox Code Playgroud)

编辑03/05/2014 我使用Macports在我的Mac上安装了unixODBC而没有任何问题.现在,当我尝试"npm install odbc --save"时,我收到以下关于sql.h缺失的错误:

npm http GET https://registry.npmjs.org/odbc
npm http 304 https://registry.npmjs.org/odbc

> odbc@0.6.3 preinstall /Users/patrick/IdeaProjects/XTL/vouchers-paid/node_modules/odbc
> node-gyp configure build

  CXX(target) Release/obj.target/odbc_bindings/src/odbc.o
In file included from ../src/odbc.cpp:25:
../src/odbc.h:29:10: fatal error: 'sql.h' file not found
#include <sql.h>
         ^
1 error generated.
make: *** [Release/obj.target/odbc_bindings/src/odbc.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Darwin 13.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /Users/patrick/IdeaProjects/XTL/vouchers-paid/node_modules/odbc
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok 
npm ERR! weird error 1
npm ERR! not ok code 0
Run Code Online (Sandbox Code Playgroud)

Juv*_*uve 6

这对我有用(OSX 10.10.2)

  1. unixODBC通过MacPorts 安装不起作用.端口本身安装并自动更新包含路径和编译器查找sql.h.但接着失败了.

  2. unixodbc通过Homebrew 安装工作.包含路径不会更新,但可以修复,如其他答案所示.

对于odbc软件包的安装,您可以使用以下shell脚本:

#!/usr/bin/env bash

SRC_ODBC=/usr/local/Cellar/unixodbc/2.3.2_1/include
export C_INCLUDE_PATH=$C_INCLUDE_PATH:$SRC_ODBC
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:$SRC_ODBC
npm install odbc
Run Code Online (Sandbox Code Playgroud)