我该如何安装socket.io

时间:2015-09-18 23:29:35

标签: node.js socket.io

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

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

    我收到了以下错误消息:

    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吗?或者我错过了安装插座的部分内容?

3 个答案:

答案 0 :(得分:2)

Socket.io已正确安装。

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

  

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

部分deps未正确安装的原因非常清楚

  

gyp ERR!堆栈错误:无法找到Python可执行文件&#34; python&#34;,您可以设置PYTHON env变量。

因此,如果您希望安装这些可选的依赖项(您可能需要),则必须在系统中安装python。

答案 1 :(得分: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/

答案 2 :(得分:1)

  

堆栈错误:无法找到Python可执行文件&#34; python&#34;,您可以设置PYTHON env变量。

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