npm install报gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.没有python环境

发布时间 2023-06-29 15:48:27作者: 强者之途
 1 gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
 2 gyp ERR! stack     at PythonFinder.failNoPython (/Users/scott/project/dx_project/front_project/workflow-frontend-elem/node_modules/node-gyp/lib/configure.js:484:19)
 3 gyp ERR! stack     at PythonFinder.<anonymous> (/Users/scott/project/dx_project/front_project/workflow-frontend-elem/node_modules/node-gyp/lib/configure.js:406:16)
 4 gyp ERR! stack     at F (/Users/scott/project/dx_project/front_project/workflow-frontend-elem/node_modules/which/which.js:68:16)
 5 gyp ERR! stack     at E (/Users/scott/project/dx_project/front_project/workflow-frontend-elem/node_modules/which/which.js:80:29)
 6 gyp ERR! stack     at /Users/scott/project/dx_project/front_project/workflow-frontend-elem/node_modules/which/which.js:89:16
 7 gyp ERR! stack     at /Users/scott/project/dx_project/front_project/workflow-frontend-elem/node_modules/isexe/index.js:42:5
 8 gyp ERR! stack     at /Users/scott/project/dx_project/front_project/workflow-frontend-elem/node_modules/isexe/mode.js:8:5
 9 gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:192:21)
10 gyp ERR! System Darwin 21.5.0
11 gyp ERR! command "/usr/local/bin/node" "/Users/scott/project/dx_project/front_project/workflow-frontend-elem/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
12 gyp ERR! cwd /Users/scott/project/dx_project/front_project/workflow-frontend-elem/node_modules/node-sass
13 gyp ERR! node -v v14.17.3
14 gyp ERR! node-gyp -v v3.8.0
15 gyp ERR! not ok
16 Build failed with error code: 1
17 npm WARN @babel/plugin-proposal-class-static-block@7.18.0 requires a peer of @babel/core@^7.12.0 but none is installed. You must install peer dependencies yourself.
18 npm WARN @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.17.12 requires a peer of @babel/core@^7.13.0 but none is installed. You must install peer dependencies yourself.
19 npm WARN @babel/helper-define-polyfill-provider@0.2.4 requires a peer of @babel/core@^7.4.0-0 but none is installed. You must install peer dependencies yourself.
20 npm WARN @babel/helper-define-polyfill-provider@0.3.1 requires a peer of @babel/core@^7.4.0-0 but none is installed. You must install peer dependencies yourself.
21 npm WARN diboot-element-admin@2.3.1 No repository field.
22 
23 npm ERR! code ELIFECYCLE
24 npm ERR! errno 1
25 npm ERR! node-sass@4.14.1 postinstall: `node scripts/build.js`
26 npm ERR! Exit status 1
27 npm ERR!
28 npm ERR! Failed at the node-sass@4.14.1 postinstall script.
29 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
30 
31 npm ERR! A complete log of this run can be found in:
32 npm ERR!     /Users/scott/.npm/_logs/2022-06-08T09_20_09_286Z-debug.log
33 scott@ScottdeMacBook-Pro workflow-frontend-elem % npm install --save-dev node-sass
34 npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
35 
36 > node-sass@4.14.1 install /Users/scott/project/dx_project/front_project/workflow-frontend-elem/node_modules/node-sass
37 > node scripts/install.js
38 
39 Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/darwin-x64-83_binding.node

 

发现一段错误提示Error: Can‘t find Python executable “python“, you can set the PYTHON env variable,这提示貌也很明显,告诉我们没有python,我在终端检查了一下果然没有。
我记得macos是自带python2.7的,于是我查阅了一下资料,发现Moterey这个版本的操作系统移出了python,需要自己去安装。好吧,认命,我装。
于是我开始使用homebrew安装python3.X。

1 # 命令大概是这样子
2 brew install python3
3 brew link python3

 

细心的我观察到报错时调用的是’python’命令,于是在.bash_profile中增加了别名配置

1 alias python3='/usr/bin/python3'
2 alias python=python3
3 alias python2=python3

 

执行brew时报错zsh: command not found: brew

需要安装brew

命令安装

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

 

1.运行命令,输入序列号时 直接回车

 2.输入大写字母:Y

 3.输入mac密码,运行脚本

 4.等待安装完成即可(若报错看下文

 若出现报错(不报错则跳过)

 报错解决:点击下载插件(https://sourceforge.net/projects/git-osx-installer/)

 

此软件安装完成之后,再次重新执行安装brew命令

最后 输入命令,查看版本

输入brew -v
能看到版本说明安装成功就可以继续使用brew去安装其他东西

 

参考链接:

(58条消息) Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.解决办法_can't find python_代码大师麦克劳瑞的博客-CSDN博客

(58条消息) Mac终端: brew command not found 解决方法_brew命令找不到_一只Black的博客-CSDN博客