前提:電腦上已安裝python,mac上默認(rèn)有一個(gè)pythone2.x的,而且可以共存不同版本的python,如果需要使用python3則需要配置相關(guān)內(nèi)容。
步驟一:找到python2.7的全路徑。(如安裝3.x的,可替換為3.x路徑)
$ type -a python2.7
python3 is /usr/local/bin/python2.7
步驟二:打開Sublime Text,進(jìn)入 Tool>Build System>New Buid System,將會(huì)打開一個(gè)文件,刪掉里面的默認(rèn)內(nèi)容,填寫自己本身的軟件。
默認(rèn)內(nèi)容:
變更內(nèi)容為:
{
"cmd": ["/usr/local/bin/python3","-u","$file"],
"env": {"LANG": "en_US.UTF-8"}
}
以上用戶配置編譯工具,把文件保存為:python2.7.sublime-build,路徑使用保存時(shí)默認(rèn)路徑。
配置中第二句是可以不用的,如果你的sublime是2但是使用python3的話,編譯輸出中文會(huì)報(bào)錯(cuò):
print("\u54c8\u54c8")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
[Finished in 0.0s with exit code 1]
步驟三:
選擇編譯方法,Tool>Build System中選擇剛剛保存的python3作為編譯方法,使用command+B或者Tools>Build編譯即可。