But when CtrlBdoes not work, Sublime Text probably can’t find the Python Interpreter. When trying to run your program, see the log and find the reference to Python in path.
The point is that it tries to run python via command line, the cmd looks like:
python -u C:\scripts\test.py
If you can’t run python from cmd, Sublime Text can’t too.
(Try it yourself in cmd, type python in it and run it, python commandline should appear)
SOLUTION
You can either change the Sublime Text build formula or the System %PATH%.
To set your %PATH%:
*You will need to restart your editor to load new %PATH%
Run Command Line* and enter this command: *needs to be run as administrator SETX /M PATH "%PATH%;<python_folder>"
for example: SETX /M PATH "%PATH%;C:\Python27;C:\Python27\Scripts"
OR manually: (preferable)
Add ;C:\Python27;C:\Python27\Scripts at the end of the string.
To set the interpreter’s path without messing with System %PATH% see this answer by ppy.
It explains (like one of the answers above) how to edit this exec.py in the default directory.
I had the problem that my PYTHON UI APPLICATION would not start. I commented out the last line from the following snipped:
# Hide the console window on Windows
startupinfo = None
if os.name == "nt":
startupinfo = subprocess.STARTUPINFO()
#startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
and, taaadaaaa, I could start my app by pressing Ctrl+B. Funny line anyways, uh? And a big thank you to whoever wrote that article ;-)
One thing to note about the aforementioned build system: you can write (and use) custom .sublime-build files or even per project build_systems clause (in your project settings). This allows you to do useful things like a fancy test runner with ANSI colors output.
For even more “full IDE” features, you can use the excellent SublimePythonIDE package:
code completion (intel)
jump to definition & object description
proper linting/pep8
supports different interpreters with virtualenv
Disclosure: I’ve contributed a PR to that package, and I use it all the time, but thereareothers.
Both Sublime’s build system and SublimeREPL (the answers above) are limited in that you can’t easily interact with the workspace variables after you run your file.
If you want to run a script, then work in a REPL-like fashion (like you would in an IDE), then I recommend having Sublime open alongside an IPython console. Using AutoHotKey (Windows) or AutoKey (Linux), you can set this up such that a single shortcut will copy the filename (or just the selected code) and then paste this in the console to run the file.