NodeJS - 使用 NPM 安装时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21365714/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:44:59  来源:igfitidea点击:

NodeJS - Error installing with NPM

node.jsnpm

提问by Shaurya Chaudhuri

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

> [email protected] 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! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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>

I am installing a certain NodeJS script - Caress. But i am not unable to. I am using Windows 8.1, can anyone tell me what is the problem i am facing, and why is this installation not working. There seems to be a problem with the buffertools dependency, thats far as i can think. Dont know how maybe fix this?

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

If i download the build from github and place it in node-modules, nothing seems to work. when i try to start, using npm start, or during implementation either.

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

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

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

> [email protected] 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! [email protected] start: `node examples/server.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the [email protected] 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>

回答by Ilan Frumer

正如下面评论的,你可能不需要在 Windows 上安装 VS,看看这个

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

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

UPDATED 02/2016

更新 02/2016

Some npm plugins need node-gypto be installed.

需要node-gyp安装一些 npm 插件。

However, node-gyphas it's own dependencies (from the github page):

但是,node-gyp有它自己的依赖项(来自 github 页面):

enter image description here

在此处输入图片说明

UPDATED 09/2016

更新 09/2016

If you're using Windows you can now install all node-gypdependencies with single command (NOTE: Run As Admin in Windows PowerShell):

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

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

and then install the package

然后安装包

 $ npm install --global node-gyp

UPDATED 06/2018

更新 06/2018

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

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

Delete your $HOME/.node-gyp directory and try again.

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

See full documentation here: node-gyp

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

回答by Tony O'Hagan

Make sure you have all the required software to run node-gyp:

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

You can configure version of Visual Studio used by node-gypvia an environment variable so you can avoid having to set the --msvs_version=2012property every time you do an npm install.

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

Examples:

例子:

  • set GYP_MSVS_VERSION=2012for Visual Studio 2012
  • set GYP_MSVS_VERSION=2013e(the 'e' stands for FREE 'express edition')
  • GYP_MSVS_VERSION=2012为 Visual Studio 2012设置
  • 设置GYP_MSVS_VERSION=2013e(“e”代表免费的“快递版”)

For the full list see - https://github.com/joyent/node/blob/v0.10.29/tools/gyp/pylib/gyp/MSVSVersion.py#L209-294

有关完整列表,请参阅 - https://github.com/joyent/node/blob/v0.10.29/tools/gyp/pylib/gyp/MSVSVersion.py#L209-294

This is still painful for Windows users of NodeJS as it assumes you have a copy of Visual Studio installed and many end users will never have this. So I'm lobbying Joyent to the encourage them to include web sockets as part of CORE node and also to possible ship a GNU gcc compiler as part of NodeJS install so we can permanently fix this problem.

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

Feel free to add your vote at:

请随时在以下位置添加您的投票:

回答by Andy

I encountered the issue with the error:

我遇到了错误的问题:

gyp ERR! configure error

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

Here is what I was doing and what finally worked.

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

Disclaimer: I am just getting my hands into Node, Angular after many years in the Java, Linux world among others...

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

Environment Description: Windows 8.1 64-bit; Cygwin; cygwin bash shell

环境说明:Windows 8.1 64位;赛格温;cygwin bash 外壳

Command used that led to error: npm install -g karma

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

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

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

Discovery: 'which python' on bash shell clearly shows '/usr/bin/python'. Now that is annoying!

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

Solution: This is only applicable to those using the environment similar to what I have, i.e. using cygwin and bash shell. Hope it helps in other environments as well but keep in mind that your kettle of tea may look a little different than mine.

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

  1. Firstly, need to set the $PYTHON shell env variable in .bashrc using the explicit windows path to the python executable and not the unix like root path (/usr/bin) used by cygwin.
  2. Secondly, and this one took a lot of trial/error and here's the gotcha! Cygwin installs python under /usr/bin (which is really a mirror of /bin on windows) with the version, i.e. (in my system) /usr/bin/python2.7.exe and then adds a link /usr/bin/python --> python2.7.exe. The problem is that gyp cannot follow this link and keeps giving the annoying error that it cannot find python even though you can find it just fine from the shell command line.
  3. With the above background now add the following line to your .bashrc
  1. 首先,需要在 .bashrc 中设置 $PYTHON shell env 变量,使用 python 可执行文件的显式 Windows 路径,而不是像 cygwin 使用的根路径 (/usr/bin) 这样的 unix。
  2. 其次,这个经历了大量的试验/错误,这就是问题所在!Cygwin在/usr/bin下安装python(实际上是windows上/bin的镜像),即(在我的系统中)/usr/bin/python2.7.exe,然后添加一个链接/usr/bin/ python --> python2.7.exe。问题是 gyp 无法遵循此链接,并不断给出无法找到 python 的烦人错误,即使您可以从 shell 命令行中找到它。
  3. 有了上面的背景,现在将以下行添加到您的 .bashrc

export PYTHON="C:/cygwin64/bin/python2.7.exe (or whatever is the version on your system)"

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

  1. Now source your .bashrc from your home directory (on cygwin)--> 'source .bashrc'
  1. 现在从你的主目录(在 cygwin 上)获取你的 .bashrc--> 'source .bashrc'

You should be fine now and gyp will find the python executable.

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

I hope this helps someone stumbling on the same or similar issue.

我希望这可以帮助在相同或类似问题上绊倒的人。

回答by tarikakyol

should be able get all node-gyp dependencies with chocolateyfor Windows

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

choco install python2
choco install visualstudioexpress2013windowsdesktop

回答by YoongKang Lim

Setup JavaScript Environment

设置 JavaScript 环境

1. Install Node.js

1. 安装 Node.js

Download installer at NodeJs website. You can download the latest V6

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

2. Update Npm

2. 更新 Npm

Npm is installed together with Node.js. So don't worry.

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

3. Install Anaconda

3.安装蟒蛇

Anaconda is the leading open data science platform powered by Python. The open source version of Anaconda is a high performance distribution of Python. It can help you to manage your python dependency. You can use it to create different python environment in the futher if you want to touch with it.

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

Node-gyp only support >= Python 2.7 and < Python 3.0

So just install the 2.7 version

Node-gyp 仅支持 >= Python 2.7 和 < Python 3.0

所以只需安装2.7版本

4. Install Node-gyp

4.安装Node-gyp

You can install with?npm:

你可以安装吗?npm

$ npm install -g node-gyp

$ npm install -g node-gyp

You will also need to install:

您还需要安装:

  • On Windows:

    • Option 1: Install all the required tools and configurations using Microsoft's?windows-build-tools?using?npm install --global --production windows-build-tools?from an elevated PowerShell or CMD.exe (run as Administrator).

    • Option 2: Install tools and configuration manually:

    • Visual C++ Build Environment:

      • Option 1: Install?Visual C++ Build Tools?using the?Default Install?option.
      • Option 2: Install?Visual Studio 2015?(or modify an existing installation) and select?Common Tools for Visual C++?during setup. This also works with the free Community and Express for Desktop editions.

      ?[Windows Vista / 7 only] requires?.NET Framework 4.5.1

    • Launch cmd,?npm config set msvs_version 2015

    If the above steps didn't work for you, please visit?Microsoft's Node.js Guidelines for Windows?for additional tips.

  • 在 Windows 上:

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

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

    • Visual C++ 构建环境:

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

      ?[仅 Windows Vista / 7] 需要?.NET 框架 4.5.1

    • 启动cmd,?npm config set msvs_version 2015

    如果以上步骤对您不起作用,请访问? Microsoft 的 Windows 的 Node.js 指南?了解更多提示。

If you have multiple Python versions installed, you can identify which Python version?node-gyp?uses by setting the '--python' variable:

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

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

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

If?node-gyp?is called by way of?npm?and?you have multiple versions of Python installed, then you can set?npm's 'python' config key to the appropriate value:

如果?node-gyp?被称为?npm? 并且?你安装了多个版本的Python,那么你可以设置?npm's 'python' 配置键到适当的值:

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

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

Future update for Node.js and npm

Node.js 和 npm 的未来更新

Download installer from their official website and direct install it. The installer will automatic help you to remove old files.

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

npm update npm

npm update npm

Future update for Python

Python 的未来更新

conda update --all

conda update --all

回答by emigenix

For Cygwin users:

对于 Cygwin 用户:

The python issue with using npmon an out-of-the-box Cygwin installation, is that node-gypis giving a misleading errordue to incomplete checking in the ../npm/node_modules/node-gyp/lib/configure.jscode.

npm开箱即用的 Cygwin 安装上使用的 python 问题node-gyp是由于代码检查不完整而产生误导性错误../npm/node_modules/node-gyp/lib/configure.js

It's due to how Cygwin treats symbolic links. It doesn't do that properly in an out-of-the box installation. So the error messages from the above code become misleading, as it complains about the PYTHONpath and not the existence of python.exe(or link of) file itself.

这是由于 Cygwin 如何处理符号链接。它在开箱即用的安装中无法正确执行此操作。因此,来自上述代码的错误消息会产生误导,因为它抱怨的是PYTHON路径而不是python.exe文件本身的存在(或链接)。

There are (at least) 2 ways to resolve this.

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

  1. Installing the Cygwin package cygutils-extraand use winln.
  2. Use native Windows CMD in Admin mode.
  1. 安装 Cygwin 包cygutils-extra并使用winln.
  2. 在管理员模式下使用本机 Windows CMD。


For (1) you can create a proper symlink from within Cygwin shell by doing these steps:

对于(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"

(Also assuming you are running the Cygwin shell as Admin.) Using apt-cygis recommended and can be found in various forms on github.

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



For (2) the resolution for out-of-the-box Cygwin users is this:

对于 ( 2) 开箱即用的 Cygwin 用户的分辨率是这样的:

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

The result should look like this:

结果应如下所示:

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

回答by Mahesh Gudadari

For windows

窗户用

Check python path in system variable. npm plugins need node-gyp to be installed.

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

open command prompt with admin rights, and run following command.

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

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

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

npm install --global node-gyp

npm install --global node-gyp

回答by Adiii

The question is already answered but these were not working in my case which is alpine Linux based OS so maybe this helps someone else.

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

I was also getting same error

我也遇到同样的错误

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

So fix by single line just add this if you are working in Dockerfile or install it in OS

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

apk add --no-cache python nodejs

in ubuntu

在 ubuntu

sudo apt-get install python3.6

Note: Node version:8

注意:节点版本:8

回答by brajesh jaishwal

install node-gyp and c++ compiler (gcc-c++).

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

回答by Maksym

Fixed with downgrading Node from v12.8.1 to v11.15.0 and everything installed successfully

修复了将 Node 从 v12.8.1 降级到 v11.15.0 并成功安装所有内容