Mac安裝和配置默認Python版本

Mac默認安裝了Python2.7 ,python

查看python版本:

python -Vgit

查看python可執行文件路徑:

which pythongithub

安裝homebrew

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

安裝python3

brew install python3curl

查看python3可執行文件路徑:

which python3url

查看python3版本:

查看python path:

pythonspa

import sys3d

sys.pathblog

(能夠看到個人python 2 被自動安裝到:/System/Library/Frameworks/Python.framework/Versions/2.7 )homebrew

exit()

查看python3 path:

python3

import sys

sys.path

(能夠看到個人python 3 被homebrew自動安裝到:/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7 )

exit

配置全局環境變量:

我把全部變量都放到全局環境變量文件/etc/profile中了,因此是在這裏修改python的默認路徑。若是你的變量是自定義文件,就去那個自定義文件裏修改吧。

sudo vi /etc/profile

:wq!  保存新增變量

更新全局配置文件:source /etc/profile

查看新增變量 : echo $PYTHON_3_PATH

固然若是你想不定義變量就直接修改默認python版本也能夠:

alias python='/usr/local/bin/python3'

便可。

若是想改回python2就:alias python=$PYTHON_2_PATH

相關文章
相關標籤/搜索