在 ubuntu 上安装 node-gyp 时出错

问题描述 投票:0回答:13
npm http 200 https://registry.npmjs.org/weak/-/weak-0.2.2.tgz
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings

> [email protected] install node_modules/weak
> node-gyp rebuild

Traceback (most recent call last):
  File "/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 18, in <module>
    sys.exit(gyp.script_main())
AttributeError: 'module' object has no attribute 'script_main'
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.11.0-15-generic
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"

gyp ERR! node -v v0.10.15
gyp ERR! node-gyp -v v0.12.1
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 weak 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 weak
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.11.0-15-generic
npm ERR! command "node" "/usr/bin/npm" "install" "[email protected]"
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.3.23
npm ERR! code ELIFECYCLE

npm ERR! not ok code 0

我没有对weak或node-gyp的直接依赖,但我想我的其他依赖项(express、phantom、ejs、aws-sdk、moment)需要它。有人遇到过这样的问题并能够解决吗?

javascript node.js ubuntu npm
13个回答
35
投票

如果您的 python 版本不是错误根源,请检查您是否安装了“gyp”。这与node-gyp中的gyp版本冲突。

apt-get remove gyp

https://github.com/TooTallNate/node-gyp/issues/363#issuecomment-32234646


35
投票

这个命令

sudo apt-get install build-essential
对我的情况有帮助。


24
投票

这就是有效的。安装过程中需要 python 2.6。

#!/bin/bash
#On Ubuntu Saucy:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.6
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 20
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10

#you can switch between 2.6 & 2.7 using:
sudo update-alternatives --config python

#Btw I installed node using ppa:chris-lea/node.js

https://github.com/TooTallNate/node-gyp/issues/363


21
投票

FWIW,我在尝试在 Ubuntu 14.04 (DigitalOcean) 上安装 Protractor 时遇到了类似的问题。重新安装 node-gyp 修复了它:

apt-get install node-gyp

11
投票

在 Ubuntu 18 上,我必须安装所需的构建库才能使其正常工作

sudo apt-get install build-essential

更新:2024 年 4 月。 在 Fresh Ubuntu 上你必须运行

sudo apt update

然后

sudo apt-get install build-essential

7
投票

以下是在 Ubuntu 系统上成功安装 node-gyp 的步骤:

1.首先,使用以下命令在Ubuntu中安装“make”构建工具:

sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y;

2.然后您需要安装适当的 C/C++ 编译器工具链。我们将使用以下命令在这里安装 GCC:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update && \
sudo apt-get install gcc-snapshot -y && \
sudo apt-get update && \
sudo apt-get install gcc-6 g++-6 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave 
/usr/bin/g++ g++ /usr/bin/g++-6 && \
sudo apt-get install gcc-4.8 g++-4.8 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave 
/usr/bin/g++ g++ /usr/bin/g++-4.8;

3.安装python 2.7版本。 (注意:node-gyp 不支持 Python 3)。

sudo apt update
sudo apt upgrade
sudo apt install python2.7 python-pip

4.最后安装node-gyp npm包:

npm install -g node-gyp

额外但不重要:如果您有任何与 Node-gyp 相关的 Atom 键盘布局问题,请再安装以下一个软件包:

sudo apt-get install libxkbfile-dev

仅此而已!现在应该可以正常工作了。


4
投票

我在 Ubuntu 16.04 上尝试安装 wikimedia 扩展 mathoid 时遇到了这个问题。

我尝试了建议的所有内容,但没有任何效果,直到我这样做:

sudo apt-get install librsvg2-2 librsvg2-dev

2
投票

在 Ubuntu 10.04 上,安装 libicu 解决了我的问题。

sudo apt-get install libicu-dev


1
投票

在 Fedora 20 上,重新安装 gyp 为我解决了这个问题。

sudo yum reinstall gyp

1
投票

我已经安装了

build-essential
。我只得跑:

sudo apt install python

0
投票

就我而言,它在 Linux-mint 19.2 上失败,由于某些原因,运行时 gcc++ 无法访问。 因此,通过安装 build-essentials 错误得到解决。 PS:

build-essential 软件包是编译 Debian 软件包所需的所有软件包的参考。它通常包括 GCC/g++ 编译器和库以及一些其他实用程序。有关构建必需包列表的信息可以在 build-essentials

上找到

0
投票

如果错误是由于“致命错误:dns_sd.h:没有这样的文件或目录” 32 | 32 #包括“, 解决它

“ sudo apt-get install libavahi-compat-libdnssd-dev ”,否则如果是由于 python2 造成的,请执行以下操作 @Manish Jangir方法


0
投票

软呢帽银蓝

rpm-ostree install make automake gcc gcc-c++
© www.soinside.com 2019 - 2024. All rights reserved.