[英]Can't find Python executable "python"
当我使用npm
安装iconv
时出现以下错误:
iconv@2.1.0 安装 /root/Dropbox/nodeApps/nodeApp/node_modules/iconv node-gyp 重建
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
并在~/.bashrc
中设置PATH
:
export PYTHONPATH=$PYTHONPATH:/Python-2.7.3
export PATH=$PATH:/Python-2.7.3
并完成. ~/.bashrc
. ~/.bashrc
对于在 Ubuntu 16.04 上遇到此问题的任何人...
node-gyp
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 安装并正确加载。
在您可以键入python
并获得有效响应的 bash 会话中,键入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
中。
有一种简单安全的方法将其放入~/.bashrc
或~/.bash_aliases
文件中:
alias python=python3
在文件中添加上述内容后,运行source ~/.bashrc
或source ~/.bash_aliases
该解决方案适用于我的 Ubuntu,请参阅此处的原始答案
安装python2.7。
apt install python2
问题是因为~/.bashrc
没有在 ssh 登录时加载。 我把PATH
vars 放到~/.bash_profile
中,没关系
有时它不仅与 NPM 有关。 因此,需要一个系统范围的解决方案。 然后,只需为“python”创建一个系统范围的符号链接到您当前的 python 路径。
例如,对于我的 Ubuntu 20 设置(是 root):
ln -s /usr/bin/python3 /usr/bin/python
然后验证符号链接:
ls -l /usr/bin/python
lrwxrwxrwx 1 root root 16 Feb 19 13:55 /usr/bin/python -> /usr/bin/python3
我有同样的问题。 你可以像这样解决它:
sudo apt install python2
npm config set python "/usr/bin/python2.7"
但是如果你不想降级python3..
npm install -g node-gyp@latest
npm config set python "/usr/bin/python3.8"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.