安装Haraka时遇到的错误gyp ERR! stack Error: spawn ENOENT的解决方案

由于win7的IIS中没有自带smtp服务,调试邮件发送程序时十分不变,找到一个free smtp server,还限制每天只能发送10封邮件。刚好在学习nodejs,所以在想nodejs上应该有开源的smtp邮件服务器,果然有很多,其中一个是Haraka,代码托管在github上,https://github.com/baudehlo/Haraka

安装Haraka很简单,使用npm即可,如下:

$npm install Haraka

但是中间报错了:

D:\nodejs\node_modules\Haraka\node_modules\node-syslog>node "D:\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at failNoPython (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:120:14)
gyp ERR! stack     at D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:83:11
gyp ERR! stack     at Object.oncomplete (fs.js:107:15)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "D:\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\nodejs\node_modules\Haraka\node_modules\node-syslog
gyp ERR! node -v v0.10.22
gyp ERR! node-gyp -v v0.11.0
gyp ERR! not ok
根据提示应该是没有安装python,google了一下,大家建议安装python2.7,所以就下载安装了python2.7,设置环境变量PYTHON为D:\Python27(安装目录)。重新执行npm,结果如下,还是报错:

D:\nodejs\node_modules\Haraka\node_modules\node-syslog>node "D:\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
gyp ERR! configure error
gyp ERR! stack Error: spawn ENOENT
gyp ERR! stack     at errnoException (child_process.js:980:11)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:771:34)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "D:\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\nodejs\node_modules\Haraka\node_modules\node-syslog
gyp ERR! node -v v0.10.22
gyp ERR! node-gyp -v v0.11.0
gyp ERR! not ok
不过这次的错误不一样了,报的错误是spawn ENOENT,说明安装的Python和PYTHON这个环境变量还是有作用,但是为什么还是报错了,再次google一下,发现很多同学安装node-gyp时都报错了,最后还是在github上找到了答案,原来需要设置的环境变量PYTHON设错了,需要设置成可执行程序文件,而不是目录,如下:

PYTHONPATH=D:\Python27
PYTHON=%PYTHONPATH%\python.exe
设置了之后重新开终端执行npm,结果如下,还是有错误:

gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (D:\nodejs\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:789:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "D:\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\nodejs\node_modules\Haraka\node_modules\node-syslog
gyp ERR! node -v v0.10.22
gyp ERR! node-gyp -v v0.11.0
gyp ERR! not ok
但是这次安装过程执行完了,最后并没有报错:

Haraka@2.2.8 node_modules\Haraka
├── daemon@1.1.0
├── npid@0.3.2
├── generic-pool@2.0.4
├── ipaddr.js@0.1.2
├── async@0.2.9
├── semver@2.2.1
├── nopt@2.1.2 (abbrev@1.0.4)
├── iconv@2.0.7
└── ldapjs@0.7.0 (assert-plus@0.1.2, asn1@0.1.11, nopt@2.1.1, bunyan@0.21.1,buffertools@1.1.0, dtrace-provider@0.2.8, pooling@0.4.5)
看来应该是安装成功了,看看能不能执行:

D:\nodejs>haraka -i d:\haraka

D:\nodejs>haraka -c d:\haraka
loglevel: LOGPROTOCOL
Starting up Haraka version 2.2.8
[INFO] [-] [core] Loading plugins
[INFO] [-] [core] Loading plugin: dnsbl
[INFO] [-] [core] loaded TLD files: 1=310 2=3854 3=161
[DEBUG] [-] [core] registered hook connect to dnsbl.hook_connect
[INFO] [-] [core] Loading plugin: data.rfc5322_header_checks
[DEBUG] [-] [core] registered hook data_post to data.rfc5322_header_checks.hook_data_post
[INFO] [-] [core] Loading plugin: helo.checks
[DEBUG] [-] [core] registered hook helo to helo.checks.helo_no_dot
[DEBUG] [-] [core] registered hook ehlo to helo.checks.helo_no_dot
[DEBUG] [-] [core] registered hook helo to helo.checks.helo_match_re
[DEBUG] [-] [core] registered hook ehlo to helo.checks.helo_match_re
[DEBUG] [-] [core] registered hook helo to helo.checks.helo_raw_ip
[DEBUG] [-] [core] registered hook ehlo to helo.checks.helo_raw_ip
[DEBUG] [-] [core] registered hook helo to helo.checks.helo_is_dynamic
[DEBUG] [-] [core] registered hook ehlo to helo.checks.helo_is_dynamic
[DEBUG] [-] [core] registered hook helo to helo.checks.helo_big_company
[DEBUG] [-] [core] registered hook ehlo to helo.checks.helo_big_company
[DEBUG] [-] [core] registered hook helo to helo.checks.helo_literal_mismatch
[DEBUG] [-] [core] registered hook ehlo to helo.checks.helo_literal_mismatch
[INFO] [-] [core] Loading plugin: mail_from.access
[DEBUG] [-] [core] registered hook mail to mail_from.access.mail_from_access
[INFO] [-] [core] Loading plugin: mail_from.is_resolvable
[DEBUG] [-] [core] plugin mail_from.is_resolvable set timeout to: 0s
[DEBUG] [-] [core] registered hook mail to mail_from.is_resolvable.hook_mail
[INFO] [-] [core] Loading plugin: max_unrecognized_commands
[DEBUG] [-] [core] registered hook connect to max_unrecognized_commands.hook_connect
[DEBUG] [-] [core] registered hook unrecognized_command to max_unrecognized_commands.hook_unrecognized_command
[INFO] [-] [core] Loading plugin: rcpt_to.access
[DEBUG] [-] [core] registered hook rcpt to rcpt_to.access.rcpt_to_access
[INFO] [-] [core] Loading plugin: rcpt_to.in_host_list
[DEBUG] [-] [core] registered hook rcpt to rcpt_to.in_host_list.hook_rcpt
[INFO] [-] [core] Loading plugin: queue/smtp_forward
[DEBUG] [-] [core] registered hook queue to queue/smtp_forward.hook_queue
[DEBUG] [-] [core] registered hook queue_outbound to queue/smtp_forward.hook_queue_outbound
[NOTICE] [-] [core] Listening on :::25
[DEBUG] [-] [core] [server] running init_master hooks
[DEBUG] [-] [core] [outbound] Creating queue directory d:\haraka\queue
[INFO] [-] [core] [outbound] Loading outbound queue from d:\haraka\queue
好像并没有报错,hoho!


总结:Python在安装nodejs模块的过程中很重要,很多模块需要用到python,而且大多数要求是2.7版本的,安装完python之后记得设置三个环境变量:

1,PATH后面增加Python的安装目录

2,增加PYTHONPATH=Python的安装目录

3,增加PYTHON=%PYTHONPATH%\python.exe


注,设置环境变量之后需要重新启动终端才生效,在终端中查看环境变量可以使用set命令。


参考:

https://github.com/TooTallNate/node-gyp/issues/277

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值