今天拉取公司前端项目之后,执行 `npm install` 后出现了一下问题
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 (D:\user\desktop\ylz\code\ylz-hd-vue\node_modules\node-sass\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (D:\user\desktop\ylz\code\ylz-hd-vue\node_modules\node-sass\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack     at callback (D:\user\desktop\ylz\code\ylz-hd-vue\node_modules\graceful-fs\polyfills.js:295:20)
gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:191:21)
gyp ERR! System Windows_NT 10.0.19044
gyp ERR! command "D:\\environment\\nodejs\\node.exe" "D:\\user\\desktop\\ylz\\code\\ylz-hd-vue\\node_modules\\node-sass\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--sass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\user\desktop\ylz\code\ylz-hd-vue\node_modules\node-sass
gyp ERR! node -v v14.18.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN webpack-dev-middleware@1.12.2 requires a peer of webpack@^1.0.0 || ^2.0.0 || ^3.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-dev-server@2.11.5 requires a peer of webpack@^2.2.0 || ^3.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\webpack\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\sass\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.14.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.14.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\14460\AppData\Roaming\npm-cache\_logs\2021-12-24T08_28_55_593Z-debug.log

报错,无法下载对应的依赖。
在控制台可以看到报错中有一句

gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.

提示我们找不到python。
但是我的电脑是有装python的,在cmd输入 python -v 也是可以显示对应的版本,我的python版本是2.7
在这里插入图片描述
后面想到之前因为nodejs的版本出现过问题,所以将nodejs卸载,重新装了一个14.18.2的版本
在这里插入图片描述
修改之后在控制台继续执行npm install,但是还是出现那个问题。便上网百度了一下
网上的资料基本为执行下面语句

npm install --global --production windows-build-tools

但是我执行之后直接卡住了,进度条一直没有反应。所以就取消了这部操作。
打开百度翻译翻译了一下这句话的意思
在这里插入图片描述
可以看到提示说我们可以设置一下python的环境变量。我之前设置过了python的环境变量,不过是设置成PYTHON_HOME的形式,按照提示我打开系统变量。
1、右键我的电脑,选择属性
在这里插入图片描述

2、在弹出的窗口中找到高级系统设置,并点击进入

3、选择环境变量
在这里插入图片描述

4、点击新建
在这里插入图片描述

5、建立 PYTHON,其中变量值改为自己电脑python的位置
在这里插入图片描述
比如我的python位置就是
在这里插入图片描述

设置完变量之后点击确定保存,然后新打开一个项目的终端(切记要新打开,否则旧的终端是识别不到你刚修改的PYTHON),执行npm install
在这里插入图片描述
至此项目的依赖下载成功。
启动项目npm run dev,项目成功启动

Logo

前往低代码交流专区

更多推荐