当我使用iconv
安装npm
时出现以下错误:
iconv@2.1.0 install / root / Dropbox / nodeApps / nodeApp / node_modules / iconv node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack at failNoPython (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:103:14)
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:42:11
gyp ERR! stack at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:43:25)
gyp ERR! stack at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:46:29)
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:57:16
gyp ERR! stack at Object.oncomplete (fs.js:107:15)
gyp ERR! System Linux 3.8.0-19-generic
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /root/Dropbox/nodeApps/nodeApp/node_modules/iconv
gyp ERR! node -v v0.10.28
gyp ERR! node-gyp -v v0.13.0
gyp ERR! not ok
npm ERR! iconv@2.1.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the iconv@2.1.0 install script.
npm ERR! This is most likely a problem with the iconv 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 iconv
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.8.0-19-generic
npm ERR! command "node" "/usr/local/bin/npm" "i"
npm ERR! cwd /root/Dropbox/nodeApps/nodeApp
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.10
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /root/Dropbox/nodeApps/nodeApp/npm-debug.log
npm ERR! not ok code 0
虽然我安装了python并且可以从控制台运行它:
# python
Python 2.7.3 (default, May 9 2014, 12:18:32)
[GCC 4.8.2] on linux2
并在PATH
中设置~/.bashrc
:
export PYTHONPATH=$PYTHONPATH:/Python-2.7.3
export PATH=$PATH:/Python-2.7.3
并完成. ~/.bashrc
答案 0 :(得分:44)
对于在Ubuntu 16.04上遇到此问题的任何人...
node-gyp
不能使用Python 3.5.X,这似乎是16.04附带的默认值。我在某地读过16.04也应该附带Python2但我在安装时找不到它。
我通过以下方式解决了上述问题:
apt-get update
apt-get install python2.7
ln -s /usr/bin/python2.7 /usr/bin/python
现在当node-gyp
寻找python
时,它会点击你的Python2.7安装并正确加载。
答案 1 :(得分:9)
在您的bash会话中,您只需输入python
并获得有效回复,请输入which python
并记下python
二进制文件的完整路径位置。获取该位置并将其放入您的PYTHONPATH
和PATH
环境变量中,但最后没有python
。
例如,which python
给了我:
/usr/local/bin/python
所以我会写:
export PYTHONPATH=$PYTHONPATH:/usr/local/bin
export PATH=$PATH:/usr/local/bin
在我的~/.bashrc
。
答案 2 :(得分:2)
问题是由于~/.bashrc
未在ssh登录时加载。我将PATH
变量放到~/.bash_profile
并且没关系
答案 3 :(得分:1)
有一个简单又安全的方法
将其放入 ~/.bashrc
或 ~/.bash_aliases
文件:
alias python=python3
在文件中添加以上内容后,运行source ~/.bashrc
或source ~/.bash_aliases
此解决方案适用于我的 Ubuntu 查看原始答案 here
答案 4 :(得分:0)
只需删除 node_modules 文件夹,然后再次运行npm install
或yarn install
。
答案 5 :(得分:0)
安装python2.7。
apt install python2