由於MacOS上的VScode默認安裝的Python版本是2.7,所以需要我們自己手動安裝Python3
從Python官網下載最新版本-安裝-設置環境變量當然是可行的,但下面要介紹的是另外一種方式:Homebrew
Homebrew是macOS的軟件包管理工具,所以不只是Python,缺失的軟件包通過它來安裝都將很方便
安裝Homebrew
Homebrew網站獲取命令行
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
復制命令行到VScode終端執行,如果報錯顯示curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
,就多執行幾遍,網上有的解決方案搞的很麻煩,其實只是上面命令行中的鏈接https://raw.githubusercontent.com/Homebrew/install/master/install不能正常訪問罷了,多刷新幾遍或者隔幾分鍾再試是可以顯示下面的信息的,這時去執行就能成功了
#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere (which is
# unsupported) you can untar https://github.com/Homebrew/brew/tarball/master
# anywhere you like.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
BREW_REPO = "https://github.com/Homebrew/brew".freeze
...
安裝中途會有個Password讓填,輸入系統登錄密碼即可
安裝會需要點時間,顯示==> Installation successful!
表示安裝成功了
安裝Python3
安裝好Homebrew后便可以使用brew命令來安裝Python3
cd /usr/local/bin/
brew install python3
安裝好后重啟VScode,點擊界面左下角的版本號
就可以在界面上方選擇你要用的版本了