Mac 上安裝Python2.7和Python3

1 安裝Xcode

xcode-select --install

2 安裝Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"


清華大學(xué)鏡像
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

接下來(lái)要正式進(jìn)入安裝Python的步驟了!
首先,輸入

python --version
打印出 Python 2.7.10 ,是mac自帶的,不需要卸載

開(kāi)始安裝:
利用homebrew搜索Python

brew search python

會(huì)有如下結(jié)果:

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.

開(kāi)始安裝:

brew install python
brew install python3

查看安裝的目錄 /usr/local/Cellar/

4 設(shè)定路徑$PATH (不和系統(tǒng)Python干擾)

執(zhí)行 
1、echo $PATH
打印出
/usr/local/opt/gettext/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

打開(kāi) 
2、sudo vim /etc/paths
系統(tǒng)會(huì)按以下順序去索引
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin

5 安裝完成,確認(rèn)結(jié)果

which python
打印出  /usr/local/bin/python和/usr/local/bin/python3 說(shuō)明安裝正確

如果想使用系統(tǒng)的Python,就輸入

/usr/bin/python

轉(zhuǎn)載自 https://blog.csdn.net/hou_manager/article/details/79555809
個(gè)人怕忘記,所以簡(jiǎn)書(shū)上抄了一份過(guò)來(lái),感謝分享。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容