【问题标题】:How can I install socket.io如何安装 socket.io
【发布时间】:2015-09-19 17:05:04
【问题描述】:

我正在研究 node 和 socket.io,但我在安装 socket.io 时遇到了问题 这是我所做的:

  1. 我创建了一个文件夹,命名为nodejs
  2. 我创建了一个 app.js(里面还没有代码)
  3. 尝试使用此命令安装套接字 `npm install socket.io

我收到了这些错误消息:

C:\wamp\www\nodejs
λ npm install socket.io
/


> bufferutil@1.1.0 install C:\wamp\www\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil
> node-gyp rebuild

|
C:\wamp\www\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil {git}{hg}
{lamb} node "C:\Program Files\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 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:103:14)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:64:11
gyp ERR! stack     at Object.oncomplete (evalmachine.<anonymous>:108:15)
gyp ERR! System Windows_NT 6.2.9200
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\wamp\www\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil
gyp ERR! node -v v0.10.35
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok
npm WARN optional dep failed, continuing bufferutil@1.1.0

> utf-8-validate@1.1.0 install C:\wamp\www\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild


C:\wamp\www\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate {git}{hg}
{lamb} node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
stack     at failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:103:14)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:64:11
gyp ERR! stack     at Object.oncomplete (evalmachine.<anonymous>:108:15)
 ERR! System Windows_NT 6.2.9200
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
cwd C:\wamp\www\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate
gyp ERR! node -v v0.10.35
ERR! node-gyp -v v1.0.1
gyp ERR! not ok
npm WARN optional dep failed, continuing utf-8-validate@1.1.0
\


> utf-8-validate@1.1.0 install C:\wamp\www\nodejs\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild

|
C:\wamp\www\nodejs\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\node_modules\utf-8-validate {git}{hg}
{lamb} node "C:\Program Files\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 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:103:14)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:64:11
gyp ERR! stack     at Object.oncomplete (evalmachine.<anonymous>:108:15)
gyp ERR! System Windows_NT 6.2.9200
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\wamp\www\nodejs\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\node_modules\utf-8-validate
gyp ERR! node -v v0.10.35
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok
npm WARN optional dep failed, continuing utf-8-validate@1.1.0

> bufferutil@1.1.0 install C:\wamp\www\nodejs\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\node_modules\bufferutil
> node-gyp rebuild


C:\wamp\www\nodejs\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\node_modules\bufferutil {git}{hg}
{lamb} node "C:\Program Files\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 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:103:14)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:64:11
gyp ERR! stack     at Object.oncomplete (evalmachine.<anonymous>:108:15)
gyp ERR! System Windows_NT 6.2.9200
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\wamp\www\nodejs\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\node_modules\bufferutil
gyp ERR! node -v v0.10.35
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok
npm WARN optional dep failed, continuing bufferutil@1.1.0
socket.io@1.3.6 node_modules\socket.io
├── has-binary-data@0.1.3 (isarray@0.0.1)
├── debug@2.1.0 (ms@0.6.2)
├── socket.io-parser@2.2.4 (isarray@0.0.1, component-emitter@1.1.2, debug@0.7.4, json3@3.2.6, benchmark@1.0.0)
├── socket.io-adapter@0.3.1 (object-keys@1.0.1, debug@1.0.2, socket.io-parser@2.2.2)
├── engine.io@1.5.2 (base64id@0.1.0, debug@1.0.3, engine.io-parser@1.2.1, ws@0.7.2)
└── socket.io-client@1.3.6 (component-bind@1.0.0, to-array@0.1.3, indexof@0.0.1, backo2@1.0.2, object-component@0.0.3, debug@0.7.4, component-emitter@1.1.2, has-binary@0.1.6, parseuri@0.0.2, engine.io-client@1.5.2)

当我检查我的文件夹时,有一个 node_modules 文件夹,里面是 socket.io。看起来没问题,但你能告诉我我是怎么得到这些错误的吗?我需要重新安装nodejs吗?还是我在安装插座时遗漏了一些部分?

【问题讨论】:

  • 详情参见NPM - Can't install socket.IO 的副本。安装 socket.io 涉及一些“构建”步骤,这些步骤需要某些工具,而不仅仅是 npm。在这种情况下,您需要在路径中安装适当版本的 Python,并且由于您使用的是 Windows,因此您还需要一些 C++ 构建工具。在 Windows 上安装所有这些的详细信息都在网上(我会看看是否能找到合适的链接)。
  • 需要注意的是npm install socket.io在这里是成功的(你可以在输出的末尾看到模块树)并且插件依赖(utf-8-validatebufferutil)是可选的没有它们,socket.io 将正常运行。拥有这些插件纯粹是一种性能优势。

标签: node.js socket.io


【解决方案1】:

Socket.io 已正确安装。

没有正确安装的是一些可选的依赖项。

npm WARN 可选 dep 失败,继续...

而且有些dep没有正确安装的原因很清楚

gyp 错误!堆栈错误:找不到 Python 可执行文件“python”,您可以设置 PYTHON 环境变量。

所以如果你想安装那些可选的依赖项(你可能想要),你必须在你的系统中安装 python。

【讨论】:

    【解决方案2】:

    安装 python 2.7 并运行

    npm config set python C:\Python27\python.exe --global
    

    参考:https://www.robertkehoe.com/2015/03/fix-node-gyp-rebuild-error-on-windows/

    【讨论】:

      【解决方案3】:

      堆栈错误:找不到 Python 可执行文件“python”,您可以设置 PYTHON 环境变量。

      确保您已安装 Python 并设置指向安装位置的环境变量。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-04
        • 2015-07-07
        相关资源
        最近更新 更多