How to build Python3 on Sublime text 3 for Mac
It is officially announced that Python3 2.x will be suspended for support. Here’s how to install Python3 for Mac. If you already have Python3 in your system, start reading part 2.
1. Install Python 3
As you’ve probably know, Python is generally installed in Mac. If you want to know what version does your Mac have, here’s how you can find out:
$ python --version
Python 2.7.10
You can download 3.x version via the following link to Python officail website https://www.python.org/downloads/mac-osx/. Open pkg file to start the installation.
2. Register Python 3.X in build system on Sublime
If you open Python 3.x on Sublime after the installtion, you will still see that the program runs 2.7 instead of the new version you just downloaded. If you want to start 3.x version, you have to register Python 3 on your new Build System.
1) Find out where Python3 was installed on your terminal via using the following command:
$ which python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
Memorize or write down the location becuase you will need to input the loation in Sublime.
2) Click Tools > Build System > New Build System
3) With the new tab, input “untitled.sublime-build” and save
{
"cmd": ["/Library/Frameworks/Python.framework/Versions/3.7/bin/python3", "-d", "$file"],
"selector": "source.python",
"file_regex": "^[ ]*File "(…*?)", line ([0–9]*)"
}
Input the location you found out on terminal in "cmd"
and save with cmd+s. I recommend to name the file with something meaningful. I used python3.sublime-build
as the file name.
FYI, the location of file on *.sublime-build
is Users/{USER_NAME}/Library/Application Support/Sublime Text 3/Packages/User
4) If the file is properly saved, you will see the saved file on your Build System menu.
3. Python3 Build Test
Write short Python code on Sublime for the test and save iwth .py
import sys
print(sys.version)
print("Hello, python!")
Click Tools > Build System > pytho3 and save with cmd+b, you will see the result as below:
You don’t need to select .py afterwards.
독자 의견
저자 @brad 에게 의견 남기기: