一、安装homebrew
- MacOS comes with Python installed already. Ensure Python’s version is 2.7.x by typing
python -V
in the Terminal. - If it’s not 2.7, install Homebrew that allows us to install various software from the CLI, by running:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Run
brew install python
to install the latest Python via Homebrew
安装pip
brew install pip
后来出现报错:提示
Error: No available formula with the name "pip" Homebrew provides pip via: `brew install python`. However you will then have two Pythons installed on your Mac, so alternatively you can install pip via the instructions at: https://pip.readthedocs.io/en/stable/installing/ cooldeMacBook-Pro:~ cool$
打开网页:显示操作
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
二、Homebrew设置代理
homebrew 使用 curl 下载的,所以只要 设置 curl的代理就可以了:
### 新建 .curlrc 文件 cooldeMacBook-Pro:~ cool$ vim ~/.curlrc ### 编辑 代理内容 并保存退出 socks5 = 127.0.0.1:1086 ## 代理内容的地址 其实也可以加上双引号 socks5 = "127.0.0.1:1080" ### 查看代理结果: liuzhizhi@lzz-rmbp|logs # curl ip.cn 当前 IP:114.110.1.38 来自:北京市 广东恒敦通信技术北京分公司 liuzhizhi@lzz-rmbp|~ # curl cip.cc IP : 114.110.1.38 地址 : 中国 北京市 数据二 : 北京市 | 广东恒敦通信技术北京分公司 URL : http://www.cip.cc/114.110.1.38 liuzhizhi@lzz-rmbp|~ # curl myip.ipip.net 当前 IP:114.110.1.38 来自于:中国 北京 北京 联通/电信
三、Homebrew设置镜像源
- 替换brew.git:
cd "$(brew --repo)" git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
- 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
- 替换Homebrew Bottles源:
就是在/.bashrc或者/.zshrc文件末尾加export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
这两个文件可以自己创建,/.bashrc和/.bash_profile都可以
四、重置源
- 重置brew.git
cd "$(brew --repo)" git remote set-url origin https://github.com/Homebrew/brew.git
- 重置homebrew-core:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://github.com/Homebrew/homebrew-core.git
参考:https://www.jianshu.com/p/005963a4d843