Set up Python 3 build system with Sublime Text 3
Solution 1
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.
Solution 2
Steps to Make Sublime Text a Python IDE (Windows)
Tested successfully on Sublime Text 3. Assuming Sublime Text and package control are already installed . . .
Install Python (python.org) and pay attention to where it is installed or choose a simple location like the C drive, agreeing to remove character limit at the end of the installation.
Install package SublimeREPL (Cntrl + Shift + P, Package Control - Install Package, SublimeREPL, Enter).
Go to Preferences, Package Settings, SublimeREPL, Settings - User.
-
Paste in the following, updating the file path to your python installation folder, as needed. You may customize these and choose whatever syntax you like (last line) but I prefer my output in plain text.
{ "default_extend_env": {"PATH":"C:\\Program Files\\Python36\\"}, "repl_view_settings": { "translate_tabs_to_spaces": false, "auto_indent": false, "smart_indent": false, "spell_check": false, "indent_subsequent_lines": false, "detect_indentation": false, "auto_complete": true, "line_numbers": false, "gutter": false, "syntax": "Packages/Text/Plain text.tmLanguage" } }
Save and close the file (SublimeREPL.sublime-settings).
Go to Tools, Build System, New Build System.
-
Replace all existing text with the following:
{ "target": "run_existing_window_command", "id": "repl_python_run", "file": "config/Python/Main.sublime-menu" }
Cntrl + S or save as "C:\Users[username]\AppData\Roaming\Sublime Text 3\Packages\User\SublimeREPL-python.sublime-build" updating username or path as needed. This should be wherever your settings and builds are stored by Sublime Text.
Go to Tools, Build System, select SublimeREPL-python.
All done--now to test. 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.
If you would like to go a step further, I highly recommend making the follow changes, to allow Sublime to reload your executed python in the same window, when you press Cntrl+B (Build), instead of it opening a new tab each time:
Add the following line in the "repl_python_run" command in (Preferences, Browse Packages) SublimeREPL\config\Python\Main.sublime-menu, right before the "external_id": "python" argument:
"view_id": "*REPL* [python]",
and then to change the line:
if view.id() == view_id
into:
if view.name() == view_id
in SublimeREPL\sublimerepl.py.
Solution 3
If you are using PyQt, then for normal work, you should add "shell":"true" value, this looks like:
{
"cmd": ["c:/Python32/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"shell":"true"
}
Solution 4
Run Python Files in Sublime Text3
For Sublime Text 3, First Install Package Control:
- Press Ctrl + Shift + P, a search bar will open
Type Install package and then press enter Click here to see Install Package Search Pic
After the package got installed. It may prompt to restart SublimeText
- After completing the above step
- Just again repeat the 1st and 2nd step, it will open the repositories this time
- Search for Python 3 and Hit enter.
- There you go.
- Just press Ctrl + B in your python file and you'll get the output. Click here to see Python 3 repo pic
It perfectly worked for me. Hopefully, it helped you too. For any left requirements, visit https://packagecontrol.io/installation#st3 here.
Solution 5
Steps for configuring Sublime Text Editor3 for Python3 :-
- Go to preferences in the toolbar.
- Select Package Control.
- A pop up will open.
- Type/Select Package Control:Install Package.
- Wait for a minute till repositories are loading.
- Another Pop up will open.
- Search for Python 3.
- Now sublime text is set for Python3.
- Now go to Tools-> Build System.
- Select Python3.
Enjoy Coding.
user3002473
Studying Pure Math at the University of Waterloo with a minor in Entrepreneurship.
Updated on July 08, 2022Comments
-
user3002473 almost 2 years
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
orpython3.sublime-build
(much of the information I found was conflicting). One tutorial suggested creating a new folder in the ST3 Packages folder calledPython
and add the build file in there, whilst other tutorials suggested leaving it in the folder calledUser
.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
toPackages
(since it wasn't there already) and added in a build file with the namePython.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