I\'m trying to get Sublime Text 3 (build 3049, if that matters) to run a Python script. A simple two liner
var = raw_input(\"Enter something: \")
print \"You
Sublime Text on its own cannot handle input via raw_input()
or input()
. The same is true of other languages as well - Ruby's gets
, Java's Scanner
class, Node's readline
class, scanf
in C, cin
in C++, etc. The easiest short-term solution is to get Package Control if you don't already have it, then install SublimeREPL. It allows you to transfer or run part or all of your code through the running REPL (you'll need to start one first).
If the code you're running doesn't play well with SublimeREPL (for instance, you're using C/C++/Java/etc. and need to compile code before it runs), or you just want to run it independently of Sublime, you'll need to make your own build system. Save the following as Packages/User/Python_cmd.sublime-build
:
{
"cmd": ["start", "cmd", "/k", "c:/python38/python.exe", "$file"],
"selector": "source.python",
"shell": true,
"working_dir": "$file_dir"
}
changing the path to your Python executable as appropriate. Then, go to Tools -> Build System
and select Python_cmd
, and when you hit CtrlB to build, a new cmd
window will open up with your file running. The /k
option returns to the command prompt, without closing the window, after your program is done running so you can examine output, tracebacks, etc.
Please note that this build system is Windows-specific.
Sublime Text does not support inputting data into a program. For working with inputs you need to install a package called SublimeREPL. Follow this:
open Sublime Text >> CTRL + P
CTRL + P will open the Package control
Then follow the following steps to run your program;
It'll open a new window, where you can give your input and get the output.