首先macOS是自帶python環(huán)境的,盡管版本比較低,先不升級,看看能不能用
1.進(jìn)入終端,隨便在github上找個爬蟲腳本,運行,譬如python run.py,這時候一般會報錯,
如?ImportError: No module named requests
原因:mac osx上默認(rèn)沒有安裝requests庫,需要安裝requests
2.安裝requests庫,用pip install?requests,這時候還是會報錯,pip: command not found
3.需要安裝pip,用curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py,然后運行sudo python get-pip.py,,這時候會有一段黃黃的警告
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運行環(huán)境太老了,現(xiàn)在不維護(hù)了,需要更新,不理他
4.pip安裝好后,安裝requests庫,sudo pip install requests
5.后面還會陸續(xù)有一些缺失庫提示,缺啥裝啥
6.最后運行你想要的py,萬事大吉
如果沒有萬事大吉,那就是某些語法不兼容老版本的python了,把python弄一弄
1.上Homebrew官網(wǎng),拷貝/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)",然后報錯
? 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ìn)入下一步
2.? git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow,
升級完homebrew-core,繼續(xù)第一步,完美Installation successful!
3.用brew doctor檢測一下,可能會有一些warning,問題不大的話,略過
4.好,開始安裝python3,用?brew install python3
5.萬事大吉