Sublime Forum

Not showing output

#1

I’m taking a Python class on an older Win7 machine. Got a new dell / win11 pro computer and installed a new paid Sublime license and installed Python 3.10.1.

Python works fine in a command window. The same app “build” (cntrl b) in Sublime produces [Finished in 156ms] but no printed output.

I created a hello world program in sublime and it produced a finished-in message but no output. Same program run in a command window said “hello”.

Is there something I did wrong with the sublime instal?

0 Likes

#2

Purposefully break your Python code so that it doesn’t compile properly and then run the build again; do you see the errors being displayed in the build output?

If yes, what you’ve done is selected the Python - Syntax Check build which, as the name suggests, only checks that the syntax of your program is correct but does not actually run it.

If that’s the case, then use Tools > Build With and choose Python instead of Python - Syntax Check.

1 Like

#3

Thanks. Your observation was spot-on. But … the new installation works differently than the old and I’d like to get to the bottom of that.
Old installation: Windows 7, Python 3.8.8, unlicensed Sublime 4126
New installation: Win 11 pro, Python 3.10.1, licensed Sublime 4126
Me: I’m a freshman so I just follow the installation instructions.

In the old installation cntrl-B always checked the code and left red comments in the program window an error in the output window if the code was wrong, OR just ran the code if it was correct. Now that I know to look under Tools/Build With, I see three options: Python, Python - Syntax Check, and Python 3. The last two work as you explained. The first one does both … syntax check and displays messages if the code is wrong AND runs the code if the code is correct. As you explained, the last two just do one thing each.

On the new installation Tools / Build With does not have the first option. I’d like the first option (the one where it both runs if successful OR produces meaningful error messages in the code if the code isn’t correct). Do you know how to make that happen?

Thanks

0 Likes

#4

Sublime only ships with a single Python build system, in a file named Python.sublime-build; it looks like this (use View Package File from the command palette and enter python build to find and open it):

{
	"cmd": ["python3", "-u", "$file"],
	"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
	"selector": "source.python",

	"env": {"PYTHONIOENCODING": "utf-8"},

	"windows": {
		"cmd": ["py", "-u", "$file"],
	},

	"variants":
	[
		{
			"name": "Syntax Check",
			"cmd": ["python3", "-m", "py_compile", "$file"],

			"windows": {
				"cmd": ["py", "-m", "py_compile", "$file"],
			}
		}
	]
}

This build contains a top level build which is named Python (because of the name of the sublime-build file) that executes the code. It also contains a single variant in the variants key named Syntax Check that only compiles the code without running it. That one will be named Python - Syntax Check because it’s a variant of the Python build.

The top level build includes a file_regex that instructs Sublime in how to detect error messages so that they can be captured, navigates and displayed in the window (if you have that setting turned on). The variant inherits that from the top level build, so that both of them will navigate errors the same way.

Your mention of a Python 3 indicates that you also have a file named Python 3.sublime-build as well; that would be a file that you put there or something put there on your behalf, but it’s not part of the core of Sublime. You can use View Package File to open and examine it as well.

If Build With only shows you a single thing named Python 3, then it doesn’t include a variants key that adds extra builds, which is why you would only see one of them and not multiple. Similarly if using that build doesn’t capture errors, then it doesn’t have a file_regex in it that allows it to know how to do that (common instructions on the internet on how to get Sublime to work with Python 3 classically forget to include that part).

The build that Sublime uses is controlled by the items in the Tools > Build System menu. Commonly you leave that set to Automatic and Sublime will choose from amongst the builds that it has available based on the type of the file. Alternately you can also specify an exact build system, if you want to use something specific.

In either scenario, if there is more than one build that might apply (such as if there are multiple builds OR some of those builds have a variant) then the first time you run a build in a window, Sublime will ask you to choose from the list of applicable builds which one you want to use, and then going forward it will keep using that build without asking you again.

At any point, you can also use Tools > Build With to force Sublime to ask you again which of the builds you would like to use (and then it will continue to use that one going forward too).

I have a full video series on Builds and how they work in Sublime if you’d like to dig into it in more detail (which includes things like how to run interactive programs, which won’t work without some extra setup)

1 Like

#5

First, I’d like to say “thank you”, even if I am late, for your detailed reply and your videos.

Second, turns out the issue WAS all my fault (of course). Hidden on a stickie note … not anything formal like class notes … says after installing Sublime and Python: Tools / Build System / New Build System. Replace everything.
{
“cmd”: [“python3”, “-u”, “$file”],
}

Which is exactly what you have in your first line but I believe the above instructions are a different file than this. Just doing what the stickie note said solve my issues. Well, at least the ones with Sublime.

0 Likes