Sublime Forum

Build broken? - Python 3 - input()

#1

It seems Build is completely broken if the code includes an input(). For example:

myname = input('Type your name: ')
print('Hello', myname)

When I build this code, for example, and type an input into the debug console, nothing happens.

Searched these forums. There seem to be conflicting answers, mainly hack workarounds — but how can such a basic feature not be included? I am using the trial version, but am not about to pay $80 for a code editor that can’t run code.

Mac, Python 3, FWIW… Could this be a setup issue on my end? Or was this feature somehow overlooked?

Thank you.

Mac OS 10.13.6, Sublime Text 3.2.1, Python 3.7.3

0 Likes

I am confused... how do I get my program to INPUT?
Sublime Input Help
Python input fonction
.py file not executing on Sublime but works well on IDLE and Terminal
Sublime not executing my py files
Sublime Text 3 is not working for python
No output in sublime text ! (for python)
Code not executing
New User getting opening to run but nothing after
Are sublime text 4 and python the same?
#2

It’s not a setup issue on your end; when Sublime launches a build system it captures the output that it generates and sends it to the output panel, but it doesn’t do anything to allow you to send input back to the running program. So if you run anything that’s in any way interactive, your program will hang waiting forever for input to appear on stdin.

The general solutions are:

  1. Create a build system that first opens a terminal and then runs your program inside of the terminal
  2. Use SublimeREPL to run your code in Sublime
  3. Use Terminus in your build system; it allows you to create an actual interactive terminal directly within Sublime.

I would generally recommend Terminus for this; it’s a little easier to set up and use than SublimeREPL is (or at least, I think so) and it’s also just handy as a terminal in general.

There will be a video going live on my YouTube channel on Monday that covers this exact thing, but there is an excerpt here that shows the problem you’re having and how to use Terminus to solve it.

In your case since you’re using Python you would want to either make the modifications to the custom sublime-build that you made or, if you didn’t create your own custom build, use View Package File to open Python/Python.sublime-build and use that as the basis of the build system following the instructions in the video.

2 Likes

Sublime Won't Print
Possible to run Perl in Sublime Text?
SyntaxError: unexpected EOF while parsing
Sublime dosent display output for complex C programs
Half output is showing
After Scanner class output never triggers?
Integer Input
Doesn't execute codes properly
Some python functions are not working
Python - Build System Issue
#3

@OdatNurd, thank you. This makes sense, and Terminus does look like a fun alternative. I will look into the solutions you’ve suggested.

0 Likes

#4

Just for the record as this seems a frequently asked question:

0 Likes

Add ability to accept user input console
#5

Sorry, I’m new to this. I have successfully installed Package Control and Terminus, but I’m lost as to how to create this as a new build so that it actually runs Terminus. I watched @OdatNurd’s video, but at the crucial moment, he just pastes some code into a ‘new build system’ window — in 4 different tabs — while referring to some previous video. It is not clear: should I be just copying his code in his ‘new build’ window? If so, which version of his code? :confused:

The documentation on the Terminus page only says:
run Terminus: Open Default Shell in View
Sorry, but run where? and how?

0 Likes

#6

In order to set this up you need to know how to create a custom build system, which also requires you to know what command you would type from a terminal to be able to run whatever program you want to run.

The video that the snippet above is referencing is this video, which covers the basics of creating a build system and how they generally work. If you’re new to build systems in general this this video covers some of the more common pitfalls you can run into when using build systems (and the video releasing on Monday, of which the above is a part, covers other common problems such as the one you’re facing now).

For your case since you’re using Python you want something like this:

{
    "target": "terminus_open",
    "cmd": ["python", "-u", "$file"],

    "selector": "source.python",
}

This is more or less identical to the version that’s provided in the video, except that the selector picks Python instead of C and the cmd runs the Python interpreter.

However if you’re using Python 3 then you need to make sure that running python runs the correct version of Python (sometimes python3 is used for this task). I assume since you can run programs currently that using python works for you already, though.

0 Likes

Int input function error
#7

@OdatNurd, thank you! I was guessing the build code would look something like what you quoted above, but wanted to be sure I understand what I’m doing. I will revisit this tomorrow, when you release your full video. Thank you again for your help and thorough explanation — much appreciated.

0 Likes

#8

Update: I got Terminus running successfully! I added the line "auto_close": false, and switched my selector to python3. Thank you forum and @OdatNurd for your patience.

Here is a remedial step-by-step, for beginners (like me). :slight_smile: Admins, feel free to edit my post if I got anything wrong:

  1. Install Package Control in Sublime Text. Simply follow the instructions here. (Copy the code from the above link, open a console in Sublime Text (View -> Show Console), and paste the copied code into the console.)

  2. Use Package Control to install Terminus. Sublime Text -> Preferences -> Package Control -> Package Control: Install Package -> Terminus (This is the Mac location of Preferences. Win/Linux should be the same, once you get into your Preferences.

  3. in Sublime: Tools -> Build System -> New Build System… Save the file with a reasonable name, and with the extension .sublime-build. The content of the file may vary, depending on your needs. I am using Python 3 (a build that I imported), so I’m referencing that in my selector. The "auto_close": false line prevents the shell from closing after running the file. Here is the content of my terminus.sublime-build file:

    {
    “target”: “terminus_open”,
    “cmd”: [“python”, “-u”, “$file”],
    “auto_close”: false,

     "selector": "source.python3",
    

    }

I hope this helps someone!

0 Likes

#9

It is not working for me I followed your steps.

0 Likes

#10

I am a newbie to Python and also followed the steps. After doing so, I opened a Terminus Shell ( Tools >> Command Palette >> (start typing Terminus and pick “Terminus: Open Default Shell in Panel”).
I can then open programs in the shell and input() commands work.

0 Likes

#11

Although there is a “You need to do this…” solution, this seems to me to be a fundamental UX problem. There are likely to be many people who are relatively new to Python trying out Sublime Text. Something as fundamental as user input is expected to work out of the box, especially as it even asks for the input and gives no clue whatsoever as to why it’s not working, just no response at all. I thought the whole thing had bugged out until I tried the “cancel build” option. The need to create a custom build system to solve this is not intuitive for a newbie. Even a fully fledged IDE like PyCharm isn’t as hard as this.

It took me quite a lot of googling and refining my search terms to even find a solution. I suspect many people will simply give up on it and use something else.

I guess what I’m saying is that it’s easy to be complacent because there’s a solution, but you really should place some importance on fixing the new user experience because you’ll be losing a lot of potential users due to this confusing problem.

2 Likes

#12

ST isn’t a Python specific tool. It’s a tool for editing code with a feature for running build scripts. People use it because it’s fast and relatively clean. Unnecessary features would detract from that. Specialist features are rightly implemented as plugins. Terminal or REPL interfaces are not central to writing code and most people don’t use them.

If you want a tool that holds your hand go find a nice Python IDE or something. ST isn’t the tool for you.

0 Likes

#13

That is quite insulting, nutjob2. I have never needed anyone to “hold my hand” when it comes to computers and I will decide what software I want to use thank you very much, not you. With that attitude I sincerely hope you are not affiliated with Sublime Text or employed by the company.

You missed my point. It does provide a Python build system OOTB which displays what appears to be a terminal, executing the code, and it doesn’t work. It really is that simple. If it’s not intended to do that, don’t make it look like it’s doing that.

I was providing what I considered to be important feedback from a UX perspective, which is often overlooked by the techies, because I care.

0 Likes

#14

You’re literally saying that ST is too hard, and that the interface is too confusing. If that isn’t a cry for help and a need for hand holding, I don’t know what is.

Now you go further and you say that the build system output panel “appears to be a terminal” although it’s clearly an editing window. Do terminals let you select and delete or edit all text freely? Why would you expect to find a terminal into an application advertised as a text editor?

This isn’t confusing to those who have spent a little time exploring ST and understanding how it’s designed. It’s actually a very simple design: it’s a text editor and you do almost everything in an edit window including command output and setting preferences. This isn’t a mistake, or a “UX” failing, it’s a conscious design decision.

Now, ST may not be for you, and you can choose what every tool you like, but my point is that you’re suggesting turning a lean, fast tool for people who edit a lot of text into another IDE for your language of choice. Why? There are other tools that do that.

And no, I don’t work for ST, I’m just a concerned citizen. This is a public forum, not a sheltered workshop. If you want to express your opinions, don’t be upset when someone expresses theirs back.

0 Likes

#15

I would vote +1 for confusion given that this is probably the top one FAQ :laughing:
I prefer to execute program/script in a real external terminal so I am not bothered though.

1 Like

#16

@geekomancer Appreciate the breakdown, as I’m also completely lost given the video and other info. I followed the steps you laid out, but nothing seems to happen once I use it as the build system. Terminus is definitely installed and the build system ends in .sublime-build. Not sure what I’m missing.

0 Likes

#17

Try this technique, I think your solution is there

Get input in sublime text

0 Likes