【MAC】Homebrew的安裝和使用
技術標籤:pyhton相關
Homebrew國內安裝
安裝Homebrew
Homebrew is the easiest and most flexible way to install the UNIX tools Apple didn’t include with OS X。
網址:https://brew.sh/index_zh-cn.html
1. 安裝指令碼
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
2. 檢查安裝
/usr/local/Homebrew/bin/brew -v
3. 解除安裝指令碼
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
4. 徹底刪除
/usr/local/bin/brew快捷方式刪除
然後把/usr/local/Homebrew資料夾刪除,然後清空回收站(不清空相當於沒刪)
5. 致謝大佬
連結: 金牛肖馬.
使用Homebrew
下載軟體
以安裝python為例子:
1. 搜尋資源:
brew search python
2. 下載源
- 臨時替換:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
- 永久替換:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~ /.bash_profile
3. 選擇下載
brew install [email protected]3.8
4. 安裝成功
==> [email protected]
Python has been installed as /usr/local/opt/[email protected]/bin/python3
Unversioned symlinks
python
,python-config
,pip
etc. pointing to
python3
,python3-config
,pip3
etc., respectively, have been installed into
/usr/local/opt/[email protected]/libexec/bin
You can install Python packages with
/usr/local/opt/[email protected]/bin/pip3 install
They will install into the site-package directory
/usr/local/lib/python3.8/site-packages
5. 驗證
$ python --version
Python 2.7.16
6. 設定環境變數
- 開啟配置檔案
vim ~/.bash_profile
- 按 i ,將python3 路徑寫入(根據自己的情況寫):
export PATH=${PATH}:/usr/local/Cellar/[email protected]/3.8.6_2/bin
alias python="/usr/local/opt/[email protected]/bin/python3"
alias pip="/usr/local/Cellar/[email protected]/3.8.6_2/bin/pip3"
吐槽:這部分折磨了我好久好久……就這兩行環境!!
-
esc → :wq → 回車
-
讓配置檔案生效
source ~/.bash_profile
- 再次檢查
$ python3
Python 3.8.6