找不到 Python 可执行文件“python”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23571257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't find Python executable "python"
提问by Maxim Yefremov
When i install iconvwith npmgot the following error:
当我安装iconv时npm出现以下错误:
[email protected] install /root/Dropbox/nodeApps/nodeApp/node_modules/iconv node-gyp rebuild
[email protected] 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! [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 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
although I installed python and can run it from console:
虽然我安装了 python 并且可以从控制台运行它:
# python
Python 2.7.3 (default, May 9 2014, 12:18:32)
[GCC 4.8.2] on linux2
and set up PATHin ~/.bashrc:
并设置PATH在~/.bashrc:
export PYTHONPATH=$PYTHONPATH:/Python-2.7.3
export PATH=$PATH:/Python-2.7.3
and done . ~/.bashrc
并做了 . ~/.bashrc
回答by huu
In your bash session where you're able to just type pythonand get a valid response, type in which pythonand note the full path location of the pythonbinary. Take that location and put that into your PYTHONPATHand PATHenvironment variables, except without the pythonat the end.
在 bash 会话中,您只需输入python并获得有效响应,输入which python并记下python二进制文件的完整路径位置。获取该位置并将其放入您的PYTHONPATH和PATH环境变量中,除非最后没有python。
For example, which pythongives me:
例如,which python给我:
/usr/local/bin/python
so I would write:
所以我会写:
export PYTHONPATH=$PYTHONPATH:/usr/local/bin
export PATH=$PATH:/usr/local/bin
in my ~/.bashrc.
在我的~/.bashrc.
回答by Maxim Yefremov
the problem was because of ~/.bashrcwas not loaded on ssh login. I put PATHvars to ~/.bash_profileand it's ok
问题是因为~/.bashrc没有在 ssh 登录时加载。我把PATHvars放到了~/.bash_profile,没关系
回答by Chase
For anyone encountering this issue on Ubuntu 16.04...node-gypcan't use Python 3.5.X which seems to the be the default that ships with 16.04. I read somewhere that 16.04 was supposed to ship with Python2 as well but I can't find it on my install.
对于在 Ubuntu 16.04 上遇到此问题的任何人...node-gyp不能使用 Python 3.5.X,这似乎是 16.04 附带的默认值。我在某处读到 16.04 也应该随 Python2 一起提供,但我在安装时找不到它。
I fixed the above issue by:
我通过以下方式解决了上述问题:
apt-get update
apt-get install python2.7
ln -s /usr/bin/python2.7 /usr/bin/python
Now when node-gypgoes looking for pythonit will hit your Python2.7 install and load correctly.
现在,当你node-gyp去寻找python它时,它会命中你的 Python2.7 安装并正确加载。
回答by Quazariun
Just delete node_modulesfolder and run npm installor yarn installagain.
只需删除node_modules文件夹并运行npm install或yarn install再次运行。

