无法找到Python可执行文件“/path/to/executable/python2.7”,您可以设置PYTHON环境变量。

16

bufferutil@1.2.1安装/home/sudthenerd/polymer-starter-kit-1.2.1/node_modules/bufferutil > node-gyp rebuild gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "/path/to/executable/python2.7", you can set the PYTHON env variable. gyp ERR! stack at failNoPython (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:401:14) gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:330:11 gyp ERR! stack at F (/usr/lib/node_modules/npm/node_modules/which/which.js:78:16) gyp ERR! stack at E (/usr/lib/node_modules/npm/node_modules/which/which.js:82:29) gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/which/which.js:93:16 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:82:15) gyp ERR! System Linux 3.13.0-74-generic gyp ERR! command "/usr/bin/nodejs" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /home/sudthenerd/polymer-starter-kit-1.2.1/node_modules/bufferutil gyp ERR! node -v v5.3.0 gyp ERR! node-gyp -v v3.2.1 gyp ERR! not ok npm WARN install:bufferutil@1.2.1 bufferutil@1.2.1 install: node-gyp rebuild npm WARN install:bufferutil@1.2.1 Exit status 1 > utf-8-validate@1.2.1安装/home/sudthenerd/polymer-starter-kit-1.2.1/node_modules/utf-8-validate > node-gyp rebuild gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "/path/to/executable/python2.7", you can set the PYTHON env variable. gyp ERR! stack at failNoPython (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:401:14) gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:330:11 gyp ERR! stack at F (/usr/lib/node_modules/npm/node_modules/which/which.js:78:16) gyp ERR! stack at E (/usr/lib/node_modules/npm/node_modules/which/which.js:82:29) gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/which/which.js:93:16 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:82:15) gyp ERR! System Linux 3.13.0-74-generic gyp ERR! command "/usr/bin/nodejs" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /home/sudthenerd/polymer-starter-kit-1.2.1/node_modules/utf-8-validate gyp ERR! node -v v5.3.0 gyp ERR! node-gyp -v v3.2.1 gyp ERR! not ok npm WARN install:utf-8-validate@1.2.1 utf-8-validate@1.2.1 install: node-gyp rebuild npm WARN install:utf-8-validate@1.2.1 Exit status 1
3个回答

37

Scott Frees的解决方案对我不起作用,但运行以下命令可以解决:

npm config set python $(which python)


1
对我来说,路径略有不同。在使用 npm config 设置路径之前,请确保检查 which python 以获取路径。 - Petr Gazarov

8
如果你使用软件包管理器安装Python,它应该已经在你的路径中了-但如果没有:可以像这样添加它:

export PATH="$PATH:/usr/local/bin/python (或者你安装Python的位置)

Node-gyp需要2.x版本,不能使用Python3(你是否安装了正确的版本?)。
请参考在Windows上运行Python以获取Node.js依赖项来确保你设置了环境变量。

实际上我正在使用Ubuntu 14.04。 - SudTheNerd
没错 - export PATH="$PATH:/usr/local/bin/python 是针对 Linux 的。看起来 Python 不在你的路径上 - 你安装它的位置需要添加到 PATH 中。 - Scott Frees
使用pyenv,我需要添加以下内容(来自https://dev59.com/pVEG5IYBdhLWcg3wRoyg#71620699的建议):export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/shims:${PATH}" - Mugshep

3

我通过升级node-sass包到与我安装的Node版本兼容的版本来解决类似的错误。

node-sass发布了一张兼容性表格,我在他们的NPM页面上找到了这个表格。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接