在ubuntu上安装node-gyp时出错

Pra*_*kar 33 javascript ubuntu node.js npm

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

> weak@0.2.2 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! weak@0.2.2 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the weak@0.2.2 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" "weak@0.2.2"
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.3.23
npm ERR! code ELIFECYCLE

npm ERR! not ok code 0
Run Code Online (Sandbox Code Playgroud)

我没有直接依赖于weak或node-gyp,但我想我的其他依赖项(express,phantom,ejs,aws-sdk,moment)需要它.任何人都面临这样的问题,并能够解决?

psc*_*eit 33

如果你的python版本不是错误的来源,请检查你是否安装了"gyp".这与node-gyp中的gyp版本相冲突.

apt-get remove gyp

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

  • 应该是一个公认的答案.降级到2.6并使用PPA是最后的选择. (4认同)

Pra*_*kar 23

这是有效的.在安装过程中需要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
Run Code Online (Sandbox Code Playgroud)

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


xpe*_*int 23

这个命令sudo apt-get install build-essential对我的情况有所帮助.

  • 在 ubuntu 18.04 中没有 build-essentials,但在早期版本的 ubuntu 中没有这个问题,感谢您的支持 (2认同)

Bri*_*ine 18

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

apt-get install node-gyp
Run Code Online (Sandbox Code Playgroud)


Man*_*gir 5

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

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

sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y;
Run Code Online (Sandbox Code Playgroud)

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;
Run Code Online (Sandbox Code Playgroud)

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

sudo apt update
sudo apt upgrade
sudo apt install python2.7 python-pip
Run Code Online (Sandbox Code Playgroud)

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

npm install -g node-gyp
Run Code Online (Sandbox Code Playgroud)

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

sudo apt-get install libxkbfile-dev
Run Code Online (Sandbox Code Playgroud)

就这样!现在应该可以正常工作了。


Bhe*_*har 5

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

sudo apt-get install build-essential
Run Code Online (Sandbox Code Playgroud)