Sublime Forum

Can't Get Python to Output in Sublime Text 3

#1

Hi, I’m brand new to programming and trying to get python3 to run in Sublime Text 3 on my MacBook Pro. I’ve installed Python3 and I know that it runs in the terminal:

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03:03:55)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

print(“Hello World”)
Hello World

And I’ve built a new system to run python3 in sublime. (Saved it as a .sublime-build file.)

{
“cmd”: ["/usr/local/bin/python3", “-u”, “$file”],
“file_regex”: “^[ ]File "(…?)”, line ([0-9]*)",
“selector”: “source.python”
}

I’ve been searching online and I’ve tried several different formats for the build system, but all of them have resulted in the same problem. When I build, the only result is this:

All I see is how long the program took to run, there is no output. I made sure to shift+command+b and command+b in order to select the system but this is the only thing I see.

I’ve tried using the default python build system (which I assume runs python 2.7 because that is pre-installed on my Mac) and the result is the same. Python doesn’t seem to work on Sublime.

I would greatly appreciate any help. I’m eager to start programming but don’t know how to get past this!
Thanks!

0 Likes

#2

Have you tried scrolling UP in the console?

0 Likes

#3

It seems that your hello_world.py view is dirty. Did you save the file before building it? Also, are you sure that you have the Python3 build system selected? Use Cmd+Shift+b to change the current build system selection.

0 Likes

#4

Yes. That doesn’t seem to be the issue

0 Likes

#5

What do you mean by “dirty”? (Sorry, I’m new to this!)
I did save the file as .py before building and I did have python3 selected. I also made sure to Cmd+Shift+B but the result was still the same.

0 Likes

#6

A file is “dirty” if it has unsaved changes; I think what @FichteFoll was getting at was to ensure that the file that’s saved on disk has your print statement in it. For example, if you created a new file, saved it while it was empty, then added the print statement and ran the program, it’s running the version on disk and not the one in the editor.

3 Likes

#7

Wow. Thank you both for pointing that out. I saved the file after making my changes and it worked. I feel a little bit dumb but I’m new to this, so thank you so much for your help.

0 Likes

#8

You might want to make sure that Tools > Save all on build is checked; with that on, any file that has unsaved changes will automatically be saved when you run a build, which saves a step (and having to remember ;)).

The setting only affects files with a name, so a newly created file that you haven’t given a name by saving won’t be included.

3 Likes

#9

Awesome. Thank you again!

0 Likes

#10

OK. I was having the exactly same problem.
it seems that what was running was just the Pre-build. the syntax checking.
If you go for ctrl+shift+b ( command+shift+b) and change it the selection from “Python - syntax checking” to “Python”.
it sorted after that.

0 Likes

#11

Thank you so much my brain was totally messed up… i was not able to figure out what was wrong i watch tons of youtube video for a fix non of thm worked (´ . .̫ . `) but somehow i found your answer and now its fixed i created an account just to thank you…i feel so relieved (〒﹏〒)(人 •͈ᴗ•͈)

0 Likes

#13

I just came from the future, and your method absolutely saved the day! Thank you so much!

0 Likes