node-sass报错问题

发布于:2025-07-04 ⋅ 阅读:(18) ⋅ 点赞:(0)
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 PythonFinder.failNoPython (/Users/zhangyu/web/yongliu/yl-form-factory/node_modules/node-gyp/lib/configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (/Users/zhangyu/web/yongliu/yl-form-factory/node_modules/node-gyp/lib/configure.js:406:16)
gyp ERR! stack     at F (/Users/zhangyu/web/yongliu/yl-form-factory/node_modules/which/which.js:68:16)
gyp ERR! stack     at E (/Users/zhangyu/web/yongliu/yl-form-factory/node_modules/which/which.js:80:29)
gyp ERR! stack     at /Users/zhangyu/web/yongliu/yl-form-factory/node_modules/which/which.js:89:16
gyp ERR! stack     at /Users/zhangyu/web/yongliu/yl-form-factory/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /Users/zhangyu/web/yongliu/yl-form-factory/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:192:21)
gyp ERR! System Darwin 24.5.0
gyp ERR! command "/Users/zhangyu/.nvm/versions/node/v14.21.3/bin/node" "/Users/zhangyu/web/yongliu/yl-form-factory/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/zhangyu/web/yongliu/yl-form-factory/node_modules/node-sass
gyp ERR! node -v v14.21.3

你的报错核心是:

❗ gyp ERR! stack Error: Can’t find Python executable “python”

✅ 原因分析:

node-sass 使用的是 node-gyp 来编译原生模块,而 node-gyp 必须依赖 Python(2 或 3) 和构建工具链。

所以你这个报错意味着:

你的系统 没有安装 Python(或未在 PATH 中),导致 node-sass 编译失败。

brew install python
which python3
python3 -V

默认 node-gyp 会尝试找 python(而不是 python3),所以如果你只有 python3 而没有 python 命令,就会报: Can’t find Python executable “python”

方法一:创建 python 到 python3 的软连接

sudo ln -s $(which python3) /usr/local/bin/python

✅ 方法二:显式告诉 node-gyp 使用哪个 Python

npm config set python $(which python3)

组合解决

brew install python
xcode-select --install
npm config set python $(which python3)

彻底移除 node-sass,改用 sass

npm uninstall node-sass
npm install sass