【问题标题】:NodeJS - Error installing with NPMNodeJS - 使用 NPM 安装时出错
【发布时间】:2014-02-17 09:32:29
【问题描述】:
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Windows\system32>npm install caress-server
npm http GET https://registry.npmjs.org/caress-server
npm http 304 https://registry.npmjs.org/caress-server
npm http GET https://registry.npmjs.org/jspack/0.0.1
npm http GET https://registry.npmjs.org/buffertools
npm http 304 https://registry.npmjs.org/jspack/0.0.1
npm http 304 https://registry.npmjs.org/buffertools

> buffertools@2.0.1 install C:\Windows\system32\node_modules\caress-server\node_
modules\buffertools
> node-gyp rebuild


C:\Windows\system32\node_modules\caress-server\node_modules\buffertools>node "G:
\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 PYT
HON env variable.
gyp ERR! stack     at failNoPython (G:\nodejs\node_modules\npm\node_modules\node
-gyp\lib\configure.js:101:14)
gyp ERR! stack     at G:\nodejs\node_modules\npm\node_modules\node-gyp\lib\confi
gure.js:64:11
gyp ERR! stack     at Object.oncomplete (fs.js:107:15)
gyp ERR! System Windows_NT 6.2.9200
gyp ERR! command "node" "G:\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\
bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Windows\system32\node_modules\caress-server\node_modules\buffert
ools
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm ERR! buffertools@2.0.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the buffertools@2.0.1 install script.
npm ERR! This is most likely a problem with the buffertools package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls buffertools
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "G:\\nodejs\\\\node.exe" "G:\\nodejs\\node_modules\\npm\\bin\\n
pm-cli.js" "install" "caress-server"
npm ERR! cwd C:\Windows\system32
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Windows\system32\npm-debug.log
npm ERR! not ok code 0

C:\Windows\system32>

我正在安装某个 NodeJS 脚本 - Caress。但我不是不能。我正在使用 Windows 8.1,谁能告诉我我面临的问题是什么,以及为什么这个安装不起作用。据我所知,buffertools 依赖项似乎存在问题。不知道如何解决这个问题?

如果我从 github 下载构建并将其放在节点模块中,似乎没有任何效果。当我尝试启动时,使用 npm start 或在实施期间。

G:\nodejs\node_modules\caress-server>npm install

G:\nodejs\node_modules\caress-server>npm start

> caress-server@0.1.1 start G:\nodejs\node_modules\caress-server
> node examples/server.js

   info  - socket.io started

module.js:340
    throw err;
          ^
Error: Cannot find module './build/Release/buffertools.node'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (G:\nodejs\node_modules\caress-server\node_modules\buf
fertools\buffertools.js:16:19)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

npm ERR! caress-server@0.1.1 start: `node examples/server.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the caress-server@0.1.1 start script.
npm ERR! This is most likely a problem with the caress-server package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node examples/server.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls caress-server
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "G:\\nodejs\\\\node.exe" "G:\\nodejs\\node_modules\\npm\\bin\\n
pm-cli.js" "start"
npm ERR! cwd G:\nodejs\node_modules\caress-server
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     G:\nodejs\node_modules\caress-server\npm-debug.log
npm ERR! not ok code 0

G:\nodejs\node_modules\caress-server>

【问题讨论】:

标签: node.js npm


【解决方案1】:
如下所述,您可能不需要在 Windows 上安装 VS,请查看

https://github.com/nodejs/node-gyp/issues/629#issuecomment-153196245

2016 年 2 月更新

某些 npm 插件需要安装 node-gyp

但是,node-gyp 有它自己的依赖项 (from the github page):

2016 年 9 月更新

如果您使用的是 Windows,您现在可以使用单个命令安装所有 node-gyp 依赖项(注意:在 Windows PowerShell 中以管理员身份运行):

 $ npm install --global --production windows-build-tools

然后安装包

 $ npm install --global node-gyp

2018 年 6 月更新

https://github.com/nodejs/node-gyp/issues/809#issuecomment-155019383

删除您的 $HOME/.node-gyp 目录并重试。

在此处查看完整文档:node-gyp

【讨论】:

  • 所以当我将它安装在 linux 机器上时。我用什么来代替 ms vc++?当我做了你提到的所有事情时,我得到了这个。 - pastebin.com/LgJEKFFS
  • 一个合适的 C/C++ 编译器工具链,比如 GCC:sudo apt-get install g++
  • @IlanFrumer 哦,我随时都喜欢 Linux,但有时我必须在客户的服务器上安装应用程序..
  • 在 Windows 上安装不依赖 VS 的 C++ 编译器不能解决这个问题吗?这样的东西是不可能找到的吗?我很困惑。
  • 感谢大家的支持,为我工作。提示:在 windows 中以管理员身份运行
【解决方案2】:

确保您拥有运行node-gyp所需的所有软件:

您可以通过环境变量配置 node-gyp 使用的 Visual Studio 版本,这样您就可以避免每次执行 npm 安装时都必须设置 --msvs_version=2012 属性。

例子:

  • 为 Visual Studio 2012 设置 GYP_MSVS_VERSION=2012
  • 设置GYP_MSVS_VERSION=2013e('e'代表FREE'express edition')

完整列表见 - https://github.com/joyent/node/blob/v0.10.29/tools/gyp/pylib/gyp/MSVSVersion.py#L209-294

这对于 NodeJS 的 Windows 用户来说仍然很痛苦,因为它假定您安装了 Visual Studio 的副本,而许多最终用户永远不会拥有它。因此,我正在游说 Joyent 鼓励他们将 Web 套接字作为 CORE 节点的一部分,并可能将 GNU gcc 编译器作为 NodeJS 安装的一部分,这样我们就可以永久解决这个问题。

欢迎在以下位置添加您的投票:

【讨论】:

  • 我刚刚(终于)让它与 VS 2015 社区版一起工作。我在 Window 10 上,64 位。我在命令提示符下使用了“npm config set msvs_version 2015 -g”(当然是在安装 VS 之后)。大多数人随着时间的推移遇到这个问题,建议使用 VS2010,有时甚至到 2013 年,但我至少用 VS2015 解决了我当前的 node-gyp 问题。我还必须“npm install -g sigmund”并从 Github 手动安装“lru-cache”。最初的问题是安装了“Utf-8-Validate”,作为 Aurelia 样本的依赖项。
【解决方案3】:

我遇到了错误的问题:

gyp ERR! configure error

gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.

这是我正在做的以及最终奏效的。

免责声明:在 Java、Linux 等领域工作多年后,我刚刚开始接触 Node、Angular...

环境描述:Windows 8.1 64-bit;赛格温; cygwin bash 外壳

导致错误的命令:npm install -g karma

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

发现:bash shell 上的“which python”清楚地显示了“/usr/bin/python”。现在这很烦人!

解决方案:这只适用于那些使用类似于我的环境的人,即使用cygwin和bash shell。希望它在其他环境中也有帮助,但请记住,您的茶壶看起来可能与我的有所不同。

  1. 首先,需要使用 python 可执行文件的显式 windows 路径而不是 cygwin 使用的类 unix 根路径 (/usr/bin) 在 .bashrc 中设置 $PYTHON shell 环境变量。
  2. 其次,这个经历了很多尝试/错误,这就是问题所在! Cygwin在/usr/bin下安装python(实际上是windows上/bin的镜像),即(在我的系统中)/usr/bin/python2.7.exe,然后添加一个链接/usr/bin/蟒蛇-> python2.7.exe。问题是 gyp 无法访问此链接并不断给出令人讨厌的错误,即它无法找到 python,即使您可以从 shell 命令行中找到它。
  3. 现在有了上述背景,将以下行添加到您的 .bashrc 中

export PYTHON="C:/cygwin64/bin/python2.7.exe(或您系统上的任何版本)"

  1. 现在从主目录(在 cygwin 上)获取 .bashrc--> 'source .bashrc'

你现在应该没事了,gyp 会找到 python 可执行文件。

我希望这可以帮助遇到相同或类似问题的人。

【讨论】:

  • 这就是在 Windows 上使用 GitBash 2.6.3 解决我的问题
【解决方案4】:

应该能够使用chocolatey for Windows 获取所有 node-gyp 依赖项

choco install python2
choco install visualstudioexpress2013windowsdesktop

【讨论】:

    【解决方案5】:

    设置 JavaScript 环境

    1。安装 Node.js

    在 NodeJs 网站下载安装程序。可以下载最新的V6

    2。更新 Npm

    Npm 与 Node.js 一起安装。所以不用担心。

    3。安装 Anaconda

    Anaconda 是由 Python 提供支持的领先开放数据科学平台。 Anaconda 的开源版本是 Python 的高性能发行版。它可以帮助您管理您的 python 依赖项。如果你想接触它,你可以用它来创建不同的python环境。

    Node-gyp 仅支持 >= Python 2.7 和

    所以只安装2.7版本

    4。安装 Node-gyp

    您可以使用npm 进行安装:

    $ npm install -g node-gyp

    您还需要安装:

    • 在 Windows 上:

      • 选项 1:通过提升的 PowerShell 或 CMD.exe(以管理员身份运行)使用 Microsoft 的 windows-build-tools 使用 npm install --global --production windows-build-tools 安装所有必需的工具和配置。

      • 选项 2:手动安装工具和配置:

      • Visual C++ 构建环境:

        • 选项 1:使用默认安装选项安装Visual C++ Build Tools
        • 选项 2:安装 Visual Studio 2015(或修改现有安装)并在安装过程中选择 Common Tools for Visual C++。这也适用于免费的 Community 和 Express for Desktop 版本。

        ? [仅限 Windows Vista / 7] 需要 .NET Framework 4.5.1

      • 启动 cmd,npm config set msvs_version 2015

      如果上述步骤对您不起作用,请访问 Microsoft's Node.js Guidelines for Windows 获取更多提示。

    如果您安装了多个 Python 版本,您可以通过设置“--python”变量来识别 node-gyp 使用哪个 Python 版本:

    $ node-gyp --python C:/Anaconda2/python.exe

    如果通过npm 调用node-gyp并且您安装了多个版本的Python,那么您可以将npm 的“python”配置键设置为适当的值:

    $ npm config set python C:/Anaconda2/python.exe

    Node.js 和 npm 的未来更新

    从他们的官方网站下载安装程序并直接安装。安装程序会自动帮你删除旧文件。

    npm update npm

    Python 的未来更新

    conda update --all

    【讨论】:

      【解决方案6】:

      gyp 错误!配置错误gyp ERR!堆栈错误:找不到 Python 可执行“python”,您可以设置 PYT HON 环境变量。

      这意味着 Python 环境。变量应该指向可执行的python文件,在我的例子中: SET PYTHON=C:\work\_env\Python27\python.exe

      【讨论】:

        【解决方案7】:

        对于 Cygwin 用户:

        在开箱即用的 Cygwin 安装中使用 npm 的 python 问题是,node-gyp 给出了误导性的 error,因为对 ../npm/node_modules/node-gyp/lib/configure.js 代码的检查不完整。

        这是由于 Cygwin 如何处理符号链接。在开箱即用的安装中,它不能正确地做到这一点。因此,来自上述代码的错误消息变得具有误导性,因为它抱怨 PYTHON 路径而不是 python.exe(或链接)文件本身的存在。

        有(至少)两种方法可以解决这个问题。

        1. 安装 Cygwin 包 cygutils-extra 并使用 winln
        2. 在管理员模式下使用本机 Windows CMD。

        对于 (1),您可以通过执行以下步骤从 Cygwin shell 中创建正确的符号链接:

        # To make the Cygwin environment treat Windows links properly: 
        # Alternatively add this to your `.bashrc` for permanent use.
        export CYGWIN=winsymlinks:nativestrict
        
        # Install Cygwin package containing "winln"
        apt-cyg install cygutils-extra
        
        # Make a proper Windows sym-link:
        cd /cygdrive/c/cygwin64/bin/
        winln.exe -s python2.7.exe python.exe
        
        # Add PYTHON as a native Windows system wide variable (HKLM) 
        setx /M PYTHON "C:\cygwin64\bin\python"
        

        (还假设您以管理员身份运行 Cygwin shell。) 推荐使用apt-cyg,可以在github上找到各种形式。


        对于 (2) 开箱即用 Cygwin 用户的分辨率如下:

        # Open a native Windows CMD in Administrator mode and:
        cd C:\cygwin64\bin\
        mklink python.exe python2.7.exe
        

        结果应该是这样的:

        C:\cygwin64\bin>ls -al python*
        lrwxrwxrwx 1 xxx            xxx   13 Jun  2  2015 python -> python2.7.exe
        lrwxrwxrwx 1 Administrators xxx   13 Aug 24 17:28 python.exe -> python2.7.exe
        lrwxrwxrwx 1 xxx            xxx   13 Jun  2  2015 python2 -> python2.7.exe
        -rwxr-xr-x 1 xxx            xxx 9235 Jun  2  2015 python2.7.exe
        

        【讨论】:

          【解决方案8】:

          适用于窗户

          检查系统变量中的 python 路径。 npm 插件需要安装 node-gyp。

          以管理员权限打开命令提示符,然后运行以下命令。

          npm install --global --production windows-build-tools

          npm install --global node-gyp

          【讨论】:

            【解决方案9】:

            修复了将 Node 从 v12.8.1 降级到 v11.15.0 并成功安装的问题

            【讨论】:

              【解决方案10】:

              我正在处理一个旧的 Vue 2.x 项目,至少有 2 年的历史,并且 deps 从未更新过。恢复到 Node v10.16.3 对我有用。版本 14 和 12 不起作用。

              【讨论】:

                【解决方案11】:

                对我来说,解决方案是:

                rm -rf  ~/.node_gyp and
                sudo npm install -g node-gyp@3.4.0
                cd /usr/local/lib sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.5.dylib 
                brew install gcc
                npm install
                

                【讨论】:

                  【解决方案12】:

                  我通过 npm install -g appium 安装 appium 并在 Windows 10 上遇到相同的错误。

                  以下命令对我有用:

                  npm --add-python-to-path='true' --debug install --global windows-build-tools
                  

                  https://github.com/felixrieseberg/windows-build-tools/issues/33

                  【讨论】:

                    【解决方案13】:

                    问题已经得到解答,但这些在我的情况下不起作用,它是基于 alpine Linux 的操作系统,所以也许这对其他人有帮助。

                    我也遇到了同样的错误

                    gyp ERR! configure error 
                    gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
                    

                    因此,如果您在 Dockerfile 中工作或将其安装在 OS 中,只需添加一行即可修复

                    apk add --no-cache python nodejs
                    

                    在ubuntu中

                    sudo apt-get install python3.6
                    

                    注意:节点版本:8

                    【讨论】:

                      【解决方案14】:

                      安装 node-gyp 和 c++ 编译器 (gcc-c++)。

                      【讨论】:

                      • 你能解释一下这比其他 11 个答案更好吗?
                      • 嗨,Stephan,当然它不是更好的那个,但是是的,在对我有用的最小步骤中。
                      【解决方案15】:

                      npm install --global --production windows-build-tools

                      【讨论】:

                        猜你喜欢
                        • 1970-01-01
                        • 1970-01-01
                        • 2015-02-01
                        • 1970-01-01
                        • 2015-01-15
                        • 2020-01-28
                        • 2017-09-12
                        • 2015-06-01
                        • 1970-01-01
                        相关资源
                        最近更新 更多