Set up Python 3 build system with Sublime Text 3

user3002473 picture user3002473 · May 19, 2014 · Viewed 130.1k times · Source

I want to configure Sublime Text 3 to build Python 3, but I don't seem to understand how the builds work. Many tutorials have told me to make a build file containing code such as:

{
    'cmd': ['/usr/bin/python3', '-u', '$file'],
    'file_regex': '^[ ]*File "(…*?)", line ([0-9]*)',
    'selector': 'source.python'
}

and save it as a file called Python.sublime-build or python3.sublime-build (much of the information I found was conflicting). One tutorial suggested creating a new folder in the ST3 Packages folder called Python and add the build file in there, whilst other tutorials suggested leaving it in the folder called User.

One tutorial explained how I had to change the Environment Variable path on my operating system to get it to work. That didn't seem to help either.


I added a folder Python to Packages (since it wasn't there already) and added in a build file with the name Python.sublime_build which featured only the code I posted above in it. Now when I attempt to run Sublime Text it gives me this error:

Error trying to parse build system:
Expected value in Packages\Python\Python.sublime-build:2:5

Answer

MattDMo picture MattDMo · May 19, 2014

The reason you're getting the error is that you have a Unix-style path to the python executable, when you're running Windows. Change /usr/bin/python3 to C:/Python32/python.exe (make sure you use the forward slashes / and not Windows-style back slashes \). Once you make this change, you should be all set.

Also, you need to change the single quotes ' to double quotes " like so:

{
    "cmd": ["c:/Python32/python.exe", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

The .sublime-build file needs to be valid JSON, which requires strings be wrapped in double quotes, not single.