Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set up Python 3 build system with Sublime Text 3

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 
like image 338
user3002473 Avatar asked May 19 '14 06:05

user3002473


People also ask

How do I create a system for Python in Sublime Text?

Open or create a simple python file, having a *. py extension and save it wherever desired. Make sure the file is open and selected in Sublime Text. Now, when you press Cntrl + B to build and run it, it will open another tab, titled "REPL [python]", executing and displaying the results of your python code.

How do I create a Build System in Sublime Text?

Sublime Text is able to run build programs such as 'make', either when a key in pressed (F7 by default), or when a file is saved. The build system to use can be select from the Tools/Build System menu. If a project is open, the selected build system will be remembered for the project.

Is Sublime Text 3 good for Python?

Sublime Text can be used for much more than Python development and there are many useful tutorials that are not targeted at a specific programming language which are still useful. Super charge your Sublime Text 3 to increase your productivity provides many shortcuts and tricks for using the editor.


1 Answers

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.

like image 183
MattDMo Avatar answered Sep 19 '22 04:09

MattDMo