npm i 在安装node-sass模块时遇到了Python相关的错误。
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable. ... Build failed with error code: 1
这是因为node-sass模块在构建过程中需要使用node-gyp工具,而node-gyp工具需要Python环境来执行构建操作。
有两种方法
一、安装Python环境:
可以安装Python并将其添加到系统的环境变量中。安装Python后,重新运行npm安装命令,node-sass模块应该能够成功构建了。
二、使用sass模块替代node-sass模块:
我这里为了省事使用sass模块替代node-sass模块,因为sass模块是一个纯JavaScript实现的Sass编译器,不需要依赖Python环境
将原来的node-sass依赖项删除
npm uninstall node-sass
然后添加sass依赖项
npm install sass
最后,重新运行npm安装命令
npm install