Problem
I want to set up a complete Python IDE in Sublime Text 2.
I’d like to know how to launch Python code directly from the editor. Is it done with the help of a build system? How do I go about doing it?
Asked by neo
Solution #1
Tools -> Build System -> (choose) Python then:
To Run:
Tools -> Build
-or-
Ctrl + B
CMD + B (OSX)
This will open your file in the editor’s console, which should be near the bottom.
To Stop:
Ctrl + Break or Tools -> Cancel Build
Fn + C (OSX)
Here’s where you can discover your Break key: http://en.wikipedia.org/wiki/Break key
Note that pressing CTRL + C will not work.
When Ctrl + Break doesn’t work, do the following:
Go to:
and then paste the following line:
{"keys": ["ctrl+shift+c"], "command": "exec", "args": {"kill": true} }
Instead of CTRL+BREAK, you can now use ctrl+shift+c.
Answered by matiit
Solution #2
% APPDATA % Sublime Text 2PythonPython.sublime-build
Change content to:
{
"cmd": ["C:\\python27\\python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Change “c:python27” to whatever version of Python you have installed on your machine.
Answered by ppy
Solution #3
Save your file with a.py extension on Mac OS X. Using the arrow keys, press + B. It is displayed in a separate window below.
Answered by bobobobo
Solution #4
CtrlB is the shortcut for RUN (answer by matiit)
However, if CtrlB does not work, Sublime Text is most likely unable to locate the Python Interpreter. When you try to start your program, look in the log for a reference to Python in the path.
[cmd: [u'python', u'-u', u'C:\\scripts\\test.py']]
[path: …;C:\Python27 32bit;…]
The point is that it attempts to launch Python from the command line, with the following cmd:
python -u C:\scripts\test.py
Sublime Text won’t run python if you can’t launch it from cmd. (Type python into cmd and hit enter; the python commandline should display.)
Either the Sublime Text build formula or the System percent PATH percent can be changed.
Answered by Qwerty
Solution #5
SublimeREPL can be used (you need to have Package Control installed first).
Answered by invis
Post is based on https://stackoverflow.com/questions/8551735/how-do-i-run-python-code-from-sublime-text-2