Use View Package File
from the command palette to open the file Python/Python.sublime-build
; this is the build system that ships with Sublime by default. Once it’s open, select everything and copy it to the clipboard (you can’t edit this file).
Now choose Tools > Build System > New Build System...
from the menu, which will create a new unsaved window with a Stub build system in it. Select all of the text and paste in the text you copied above, then do a save.
Sublime’s going to ask you what you want to name the file. Name it something like Python3.sublime-build
or My Custom Python.sublime-build
, etc (basically anything other than Python.sublime-build
. Make sure the file you save as the sublime-build
extension. It should also be in your User
package, but if you follow these steps, Sublime will store it there by default.
Now that you have a duplicate build system, in both of the shell_cmd
lines, replace python
with python3
(or whatever the name of your interpreter is). What you put here depends on what you need to type in a terminal in order to execute Python 3. (note: You don’t need to try to throw any path information in there such as is suggested in that link, unless your system isn’t set up correctly; just literally changing python
to python3
in those two lines should be enough). Then save the file again.
Now you want to go to Tools > Build System
in the menu and either select Automatic
or the item with the name that represents the file that you just saved. Don’t pick Python
here; that will get you the default build (you chose a different name above to ensure that it would be easy to determine which one is yours).
Now in a Python file (Sublime has to know it’s Python, so save the file to disk as a .py
extension) when you use Tools > Build
or the associated key, a build will trigger. You’re going to be offered a panel with several options (depending on whether chose Automatic
or not above). Pick the entry that’s named for the name of your file, not the one that says - Syntax Check
; that will compile your program and not run it.
This box will only appear once; Sublime will remember your choice. If you ever need to change it, use Tools > Build With
instead of Tools > Build
and it will ask you again.
Final notes:
-
Sublime is executing an external program (in this case python
/python3
) to do the work. So you need to make sure that your file is saved on disk. If you don’t, you’re going to get weird errors the first time. Once you save the file once and it has a name, as long as Tools > Save all on build
is checked, you never have to worry about it again (otherwise, save before building every time unless you want surprises. But you always have to save at least once first).
-
If you’re planning on running any code that uses something like input()
or anything where as a part of your program you’re going to need to give some sort of input to your program, it’s not going to work. Sublime doesn’t support that without further setup work. Fortunately it’s easy to do with the Terminus package; see this video for instructions.