Homebrew更换清华源或中科大源及重置默认源 & pip 换源

Homebrew作为MacOS系统的管理器方便了软件安装及更新,但是使用过程中会遇到下载特别慢,brew update无反应等问题,这是因为资源在外网上,需通过更改源来改为国内的镜像地址,提高下载速度。
目前国内流行的镜像源有两个:清华源中科大源,更改的方法是相同的,以下为详细步骤:

  • 更换源需重置三个地方:
    • brew.git
    • homebrew-core.git
    • homebrew-bottles

更换为清华源/中科大源

Step1. 重置brew.git

$ cd "$(brew --repo)"
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
#清华源:
#$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
#中科大源:
#git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

Step2. 重置homebrew-core.git核心软件仓库

$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
#清华源:
#$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
#中科大源:
#git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

Step3. 重置homebrew-cask.git源

$ cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

如果想换回原来的默认源,步骤如下:

重置默认源(github)

#‘’‘step1.重置brew.git’‘’
$ cd "$(brew --repo)"
#git remote -v #查看当前源
$ git remote set-url origin https://github.com/Homebrew/brew.git

#‘’‘step2.重置homebrew-core.git核心软件仓库’‘’
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://github.com/Homebrew/homebrew-core.git

#‘’‘Step3. 重置homebrew-cask.git源’‘’
$ cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
$ git remote set-url origin https://github.com/Homebrew/homebrew-cask

官网参考

清华源使用帮助
中科大源使用帮助


brew install安装时报错

Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

原因

因为修改了用户名,之前brew是在admin下安装的,但是现在换了名字,就出现了这个问题. 其实就是文件的属组和用户无法辨识了

方案

sudo chown -R `whoami` /usr/local/Homebrew/
sudo chown -R $(whoami) $(brew --prefix)/*
sudo mkdir /usr/local/Frameworks
sudo chown -R `whoami` /usr/local/Frameworks/


pip下载推荐临时换源的方法

用pip管理工具安装库文件时,默认使用国外的源文件,因此在国内的下载速度会比较慢,可能只有50KB/s。幸好,国内的一些顶级科研机构已经给我们准备好了各种镜像,下载速度可达2MB/s。
其中,比较常用的国内镜像包括:

  • 阿里云 http://mirrors.aliyun.com/pypi/simple/
  • 豆瓣 http://pypi.douban.com/simple/
  • 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
  • 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
  • 华中科技大学 http://pypi.hustunique.com/

方法也很简单:pip install [formula] -I [url]

$ pip3 install opencv-python -i  https://pypi.tuna.tsinghua.edu.cn/simple/
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值