繁体   English   中英

NodeJS - 使用 NPM 安装时出错

[英]NodeJS - Error installing with NPM

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>
正如下面评论的,你可能不需要在 Windows 上安装 VS,看看这个

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

更新 02/2016

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

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

在此处输入图片说明

更新 09/2016

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

 $ npm install --global node-gyp

然后安装包

 $ npm install --global node-gyp

更新 06/2018

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

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

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

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

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

例子:

  • 为 Visual Studio 2012 设置GYP_MSVS_VERSION=2012 2012
  • 设置GYP_MSVS_VERSION=2013e (“e”代表免费的“快递版”)

有关完整列表,请参阅 - 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 安装的一部分发布,以便我们可以永久解决此问题。

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

我遇到了错误的问题:

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位; 赛格温; cygwin bash 外壳

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

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

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

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

  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(或系统上的任何版本)"

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

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

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

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

choco install python2
choco install visualstudioexpress2013windowsdesktop

设置 JavaScript 环境

1. 安装 Node.js

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

2. 更新 Npm

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

3.安装蟒蛇

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

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

所以只需安装2.7版本

4.安装Node-gyp

您可以使用npm安装:

$ npm install -g node-gyp

您还需要安装:

  • 在 Windows 上:

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

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

    • Visual C++ 构建环境:

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

      💡 [仅适用于 Windows Vista / 7] 需要.NET Framework 4.5.1

    • 启动 cmd, npm config set msvs_version 2015

    如果上述步骤对您不起作用,请访问Microsoft 的 Windows Node.js 指南以获取其他提示。

如果您安装了多个 Python 版本,您可以通过设置 '--python' 变量来确定node-gyp gyp 使用的 Python 版本:

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

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

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

Node.js 和 npm 的未来更新

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

npm update npm

Python 的未来更新

conda update --all

对于 Cygwin 用户:

在开箱即用的 Cygwin 安装上使用npm的 python 问题是,由于../npm/node_modules/node-gyp/lib/configure.js检查不完整, node-gyp ../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

窗户用

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

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

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

npm install --global node-gyp

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

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

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

对我来说,解决方案是:

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

我正在通过 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

问题已经得到解答,但这些在我的情况下不起作用,这是基于 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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM