brew命令不能正常使用

起因

想尝试一下https://github.com/AUTOMATIC1111/stable-diffusion-webui,但是运行./webui.sh报错了:大概是gfpgan安装不上。

定位到launch.py.227:

gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379")

然后修改为:

gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "https://github.com/TencentARC/GFPGAN.git")

不行。

在./stable-diffusion-webui和./stable-diffusion-webui/venv/lib/pyhton3/site-packages/都手动git clone https://github.com/TencentARC/GFPGAN.git 还是不行。

遂放弃。

后记:

添加https://ghproxy.com/即可

gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "https://ghproxy.com/https://github.com/TencentARC/GFPGAN.git")

居然是网络问题,看报错根本看不出来!啊 哒哒哒!

中途可能使用了该命令:

git config --global --unset http.proxy

git config --global --unset https.proxy

经过

第二天,就不能正常使用brew相关的命令了。(brew update会涉及到git fetch更新一些仓库的命令)

但最近有在这上面有需求,就不能回避了

下面为我踩坑时常看到的信息:

brew update --verbose

Checking if we need to fetch /opt/homebrew...
Fetching /opt/homebrew...
Checking if we need to fetch /opt/homebrew/Library/Taps/carlocab/homebrew-personal...
Checking if we need to fetch /opt/homebrew/Library/Taps/dart-lang/homebrew-dart...
Checking if we need to fetch /opt/homebrew/Library/Taps/grpc/homebrew-grpc...
Checking if we need to fetch /opt/homebrew/Library/Taps/homebrew/homebrew-cask...
Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-cask...
Checking if we need to fetch /opt/homebrew/Library/Taps/homebrew/homebrew-cask-versions...
Checking if we need to fetch /opt/homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-core...
Checking if we need to fetch /opt/homebrew/Library/Taps/homebrew/homebrew-services...
Checking if we need to fetch /opt/homebrew/Library/Taps/mongodb/homebrew-brew...
Checking if we need to fetch /opt/homebrew/Library/Taps/probezy/homebrew-core...
Fetching /opt/homebrew/Library/Taps/dart-lang/homebrew-dart...
Fetching /opt/homebrew/Library/Taps/grpc/homebrew-grpc...
Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-cask-versions...
Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-services...
Fetching /opt/homebrew/Library/Taps/mongodb/homebrew-brew...
Fetching /opt/homebrew/Library/Taps/probezy/homebrew-core...
Fetching /opt/homebrew/Library/Taps/carlocab/homebrew-personal...
fatal: unable to access 'https://github.com/mongodb/homebrew-brew/': Failed to connect to github.com port 443 after 75008 ms: Couldn't connect to server
fatal: unable to access 'https://github.com/carlocab/homebrew-personal/': Failed to connect to github.com port 443 after 75003 ms: Couldn't connect to server
fatal: unable to access 'https://github.com/dart-lang/homebrew-dart/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
fatal: unable to access 'https://github.com/Homebrew/homebrew-cask-versions/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
fatal: unable to access 'https://github.com/probezy/homebrew-core/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
fatal: unable to access 'https://github.com/Homebrew/homebrew-services/': error:02FFF036:system library:func(4095):Connection reset by peer
fatal: unable to access 'https://github.com/grpc/homebrew-grpc/': error:02FFF036:system library:func(4095):Connection reset by peer

中途把github的代理弄了好几个版本,也改过DNS8.8.8.8+重启。

把brew改成清华镜像也不是很有用。

解决方案

最后的解决方案是:

step1:

没改DNS,brew镜像.

下面为brew config的输出,以供参考

HOMEBREW_VERSION: 4.0.3-32-ga3207a0
ORIGIN: https://github.com/Homebrew/brew
HEAD: a3207a03900d7b012c999fad911a701baed82be5
Last commit: 4 hours ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 3e0f7cf00d2e1b9ea58aeee6009c3c98dd3fc3fe
Core tap last commit: 47 minutes ago
Core tap branch: master
Core tap JSON: 22 Feb 07:36 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_BOTTLE_DOMAIN: https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
HOMEBREW_CASK_OPTS: []
HOMEBREW_GITHUB_API_TOKEN: set
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 14.0.0 build 1400
Git: 2.37.1 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.86.0 => /usr/bin/curl
macOS: 13.2.1-arm64
CLT: 14.2.0.0.1.1668646533
Xcode: N/A
Rosetta 2: false

step2:

修改github的代理为clash的端口(mixed-port为7890,或socks5:7891)。
最后我的/Users/changqingaas/.gitconfig文件为:

[user]
	name = chang_qing_aas
	email = 1736731090@qq.com
[safe]
	directory = /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
[core]
	quotepath = false
[filter "lfs"]
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
	required = true
[http]
	version = HTTP/1.1
	proxy = socks5://127.0.0.1:7891
[https]
	proxy = socks5://127.0.0.1:7891
[http "https://github.com"]
	proxy = socks5://127.0.0.1:7891
[https "https://github.com"]
	proxy = socks5://127.0.0.1:7891

具体命令我没保存,如果觉得有用直接vim .gitconfig修改吧。

我还改了.ssh/config:

Host github.com
   HostName github.com
   User git
   #socks5
   ProxyCommand nc -X 5 -x 127.0.0.1:7891 %h %p

在/etc/config添加:

# Github
140.82.114.3 github.com

185.199.110.133 raw.github.com

185.199.110.133 raw.githubusercontent.com

199.232.69.194 github.global.ssl.fastly.net

185.199.108.153 assets-cdn.github.com

185.199.109.153 assets-cdn.github.com

185.199.110.153 assets-cdn.github.com

step3:

我在brew cleanup 遇到”Failed to download https://formulae.brew.sh/api/cask.json
这个文件不知道为啥下载很慢,以前没这个问题。
使用wget测出需要好几十个小时,才能下完。
猜测是终端不能翻墙的原因。
遂google
在这里看到解决办法:https://github.com/Homebrew/brew/issues/14516
我做了如下:

rm -r "$(brew --cache)/api" # /Users/changqingaas/Library/Caches/Homebrew/api
export HOMEBREW_NO_INSTALL_FROM_API=1

成功了,绕过了这个文件下载很慢的问题。

但是,当我

brew upgrade

发现了下载速度很慢,不知道这和之前改到清华镜像是否有原因。

==> Fetching node@16
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/node%4016-
######################################################################## 100.0%

step4:

到这里事情并没有结束。

wget https://formulae.brew.sh/api/formula.json

速度依然很慢。

但是,基本每条brew指令都需要下载该文件。

实践后,可知:每次运行brew命令前,可以执行

export HOMEBREW_NO_INSTALL_FROM_API=1

执行之后,基本就能使用brew命令了。不过这样只能起到短期效果。

长期解决办法是:把它写进.zshrc or .bash_profile;source一下。

结尾

git命令翻墙和终端翻墙可能仍是问题。