My question is, can Sublime 3 be setup to run the code that has been written with in Sublime. I've have searched on here and the internet and have tried numerous different suggestions. If the answer has already been posted and someone could point me in the proper direction / URL I'd appreciate it. If it cannot be done and you have other suggestion's I'll give it a try.
4 Answers
The following steps do work for Sublime Text 2 and 3. What you need is a so-called Sublime Text Build System which is represented by a valid JSON text file. There are a lot of Q and A to this topic on the internet. Anyway, here is a step-by-step list.
FYI: As far as I know there is no updated Syntax file for Python3.5 for Sublime Text. If anyone knows of an update, please let me know in the comment section.
Mac and Linux:
- Open Sublime Text
- In the menu bar go to
Tools -> Build-System -> New Build System
Paste the following code-snippet to the new opened file. Verify that the path to your python 3.5 installation is correct, otherwise see step 4.
{ "cmd": ["/Library/Frameworks/Python.framework/Versions/3.5/bin/python3", "-u", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python" }
If you don't know the location of Python 3 try to execute 'which python3' in your terminal. Also verify that the correct python3 command is in your search-path. Here is some example output:
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
Save the file using (e.g using
cmd (⌘) + s
on your keyboard) and enter a filename likePython-3.5.sublime-build
.Now you can switch to your new build-system. By using (
cmd + b
) you can execute your Python script now.
Windows:
- Open Sublime Text
- In the menu bar go to
Tools -> Build-System -> New Build System
Paste the following code-snippet to the new opened file. You need to verify that the path to
python.exe
is correct, otherwise update it.{ "cmd": [r"C:\Python35\python.exe", "-u", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python" }
Save the file using (e.g using
CTRL + s
on your keyboard) and enter a filename likePython-3.5.sublime-build
.Now you can switch to your new build-system. By using (
CTRL + b
) you can execute your Python script now.

- 2,392
- 3
- 31
- 68
-
Thank you for the response, is the above answer based on having package control or any other add on's installed to Sublime 3 ? – Michael1775 Oct 19 '15 at 12:02
-
No, no packages or plugins needed. – HelloWorld Oct 19 '15 at 12:02
-
Thank you again "HelloWorld" I followed the instructions for the Mac and did some basic coding, then Ctrl B and the output displayed at the bottom, I did not read the documentation in full yet for sublime 3. Thank you – Michael1775 Oct 20 '15 at 02:05
For python 3.6
i'm using:
{
"cmd": ["/usr/local/bin/python3.6", "$file"]
}
And everything works fine! Don't forget to get full path to your python interpreter.

- 5,163
- 2
- 33
- 40
Yes sublime can execute code in python3.
Sublime text executes the python file using system python available.
All you need to do is make python3 is default in your system. You can do this by adding setting PATH
variable to point to python3.
To execute code:
Tools -> Build
CMD + B
-
Thank you all for the reply's. I followed what was listed here and made a build for the 2 different python OS's on the computer. Now I am working on how to run from sublime and call the terminal / python3 execute file name? as a all in one, instead of the switching to terminal. Keeping it simple and straight forward is the goal. Thank you all – Michael1775 Nov 20 '16 at 23:38
By using the following code:
{
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
would make the Sublime work.
Save the file as python3.sublime-build
then select it in Tools -> build system -> Python3
.
At last, run it by pressing command + B.