Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.解决办法
背景:生产环境发布前端项目报如下错误
执行npm i命令执行如下错误
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
这提示貌也很明显,告诉我们没有python,我在终端检查了一下果然没有,于是安装python
rpm -ql python
yum install python -y
继续执行npm install,发现又有了新的错误
gyp ERR! stack Error: EACCES: permission denied, mkdir '/data/jenkins_home/workspace/gk-bms-dashboard-web-prod/node_modules/node-sass/.node-gyp'
原因分析:当前目录没有读写权限。
解决方案:编辑任务,在npm install命令后添加node-sass --unsafe-perm=true,保存任务,然后再次执行任务。
npm i node-sass --unsafe-perm=true
等待执行又报如下错误
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/data/jenkins_home/workspace/gk-bms-dashboard-web-prod/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:400:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Linux 4.18.0-240.10.1.el8_3.x86_64
gyp ERR! command "/data/devtool/nodejs/bin/node" "/data/jenkins_home/workspace/gk-bms-dashboard-web-prod/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /data/jenkins_home/workspace/gk-bms-dashboard-web-prod/node_modules/node-sass
gyp ERR! node -v v14.17.5
gyp ERR! node-gyp -v v8.4.1
gyp ERR! not ok
这个错误信息表明在构建过程中遇到了问题,具体是在使用 node-gyp 编译 node-sass 时失败了。检查构建工具是否安装,gcc-c++未安装,make已经安装,接下来只需要安装rpm -ql gcc-c++
rpm -ql gcc-c++
rpm -ql make
yum install -y gcc-c++
再次执行如下:
npm i node-sass --unsafe-perm=true
一波三折,终于编译成功
评论区