1 安裝Xcode
xcode-select --install
2 安裝Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
清華大學鏡像
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
brew update
3 安裝Python
接下來要正式進入安裝Python的步驟了!
首先,輸入
python --version
打印出 Python 2.7.10 ,是mac自帶的,不需要卸載
開始安裝:
利用homebrew搜索Python
brew search python
會有如下結果:
app-engine-python gst-python python ? wxpython
boost-python ipython python-markdown zpython
boost-python3 ipython@5 python-yq
boost-python@1.59 micropython python@2 ?
==> Casks
awips-python kk7ds-python-runtime mysql-connector-python
If you meant "python" specifically:
It was migrated from homebrew/cask to homebrew/core.
開始安裝:
brew install python
brew install python3
查看安裝的目錄 /usr/local/Cellar/
4 設定路徑$PATH (不和系統Python干擾)
執行
1、echo $PATH
打印出
/usr/local/opt/gettext/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
打開
2、sudo vim /etc/paths
系統會按以下順序去索引
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin
5 安裝完成,確認結果
which python
打印出 /usr/local/bin/python和/usr/local/bin/python3 說明安裝正確
如果想使用系統的Python,就輸入
/usr/bin/python
轉載自 https://blog.csdn.net/hou_manager/article/details/79555809
個人怕忘記,所以簡書上抄了一份過來,感謝分享。