NodeJS 找不到Python可执行文件“python”

q7solyqu  于 11个月前  发布在  Node.js
关注(0)|答案(7)|浏览(175)

当我安装iconvnpm得到以下错误:
email protected(https://stackoverflow.com/cdn-cgi/l/email-protection) 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

字符串
虽然我安装了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

zy1mlcev

zy1mlcev1#

对于任何在Ubuntu 16.04上遇到此问题的人...
node-gyp不能使用Python 3.5.X,这似乎是16.04的默认值。我在某个地方读到16.04应该也会与Python 2一起发布,但我在安装时找不到它。
我通过以下方式修复了上述问题:

apt-get update     
apt-get install python2.7    
ln -s /usr/bin/python2.7 /usr/bin/python

字符串
现在,当node-gyp查找python时,它将正确地命中您的Python2.7安装和加载。

e1xvtsh3

e1xvtsh32#

在你的bash会话中,你可以只输入python并得到一个有效的响应,输入which python并记下python二进制文件的完整路径位置。把这个位置放在你的PYTHONPATHPATH环境变量中,除了最后没有python
例如,which python给出了:

/usr/local/bin/python

字符串
所以我会写:

export PYTHONPATH=$PYTHONPATH:/usr/local/bin
export PATH=$PATH:/usr/local/bin


我的~/.bashrc

woobm2wo

woobm2wo3#

有一个简单而安全的方法将其放入~/.bashrc~/.bash_aliases文件:

alias python=python3

字符串
在文件中添加上述内容后,运行source ~/.bashrcsource ~/.bash_aliases
此解决方案适用于我的Ubuntu,请参阅原始答案here

chy5wohz

chy5wohz4#

安装python2.7。
第一个月

ttygqcqt

ttygqcqt5#

我也有同样的问题。你可以这样解决:

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"

1dkrff03

1dkrff036#

这个问题是因为~/.bashrc在ssh登录时没有加载。我把PATH的变量放到~/.bash_profile上,没有问题。

pcww981p

pcww981p7#

有时候它不仅仅与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

相关问题