首先macOS是自帶python環(huán)境的絮缅,盡管版本比較低未状,先不升級(jí),看看能不能用
1.進(jìn)入終端于毙,隨便在github上找個(gè)爬蟲(chóng)腳本皮迟,運(yùn)行搬泥,譬如python run.py,這時(shí)候一般會(huì)報(bào)錯(cuò),
如?ImportError: No module named requests
原因:mac osx上默認(rèn)沒(méi)有安裝requests庫(kù)伏尼,需要安裝requests
2.安裝requests庫(kù)忿檩,用pip install?requests,這時(shí)候還是會(huì)報(bào)錯(cuò)爆阶,pip: command not found
3.需要安裝pip燥透,用curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py,然后運(yùn)行sudo python get-pip.py辨图,班套,這時(shí)候會(huì)有一段黃黃的警告
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
WARNING: The directory '/Users/esttian/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
大致意思是,你機(jī)器上的python運(yùn)行環(huán)境太老了故河,現(xiàn)在不維護(hù)了吱韭,需要更新,不理他
4.pip安裝好后鱼的,安裝requests庫(kù)理盆,sudo pip install requests
5.后面還會(huì)陸續(xù)有一些缺失庫(kù)提示,缺啥裝啥
6.最后運(yùn)行你想要的py凑阶,萬(wàn)事大吉
如果沒(méi)有萬(wàn)事大吉猿规,那就是某些語(yǔ)法不兼容老版本的python了,把python弄一弄
1.上Homebrew官網(wǎng)宙橱,拷貝/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"姨俩,然后報(bào)錯(cuò)
? homebrew-core is a shallow clone.
To `brew update`, first run:
? git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
大致意思,還是要升級(jí)养匈,進(jìn)入下一步
2.? git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow哼勇,
升級(jí)完homebrew-core,繼續(xù)第一步呕乎,完美Installation successful!
3.用brew doctor檢測(cè)一下,可能會(huì)有一些warning陨晶,問(wèn)題不大的話猬仁,略過(guò)
4.好帝璧,開(kāi)始安裝python3,用?brew install python3
5.萬(wàn)事大吉