Sublime Forum

Can't find '__main__' module in ''

#1

Hi I’m very new to programming and I want to try Python 3 with Sublime 3. But I can’t get it to work at all. When I try to build it says this:

C:\Windows\system32\python.exe: can't find '__main__' module in '' [Finished in 0.2s with exit code 1] [shell_cmd: python -u ""] [dir: C:\Program Files\Sublime Text 3] [path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static]

I installed Python 3.3 and Sublime 3 Build 3059

The code I try to build is just a simple print "Hello, world!"

I also tried it on my laptop but with the same results. I’ve tried googling it but I can’t find anything that’s simple enough for me to understand, a lot of it seems to be on Linux as well. The only thing I found out was that copying the Python.exe to system32 should work, I’ve done that and it doesn’t work. I’ve also seen something about changing a path, no clue what that is either.

Someone please help me? :cry:

2 Likes

#2

In python > 3.0

print is a regular function so its used like this:
print(‘hello world’)

not like this
print ‘hello world’

So if you are starting, better use a tutorial for python 3 and not one for python 2.x

0 Likes

#3

[quote=“monobotsoft”]In python > 3.0

print is a regular function so its used like this:
print(‘hello world’)

not like this
print ‘hello world’

So if you are starting, better use a tutorial for python 3 and not one for python 2.x[/quote]

Okay I tried to do that instead and it gave me the same result. Still can’t find ‘main’ module in ‘’ :confused:

0 Likes

#4

Lighthammer,
Welcome! First of all, you need to SAVE your code file with the “.py” extension. Then, on the ‘Tools/Build System’ menu, make sure your build system is set to either ‘auto’ or ‘Python’. What that message is telling you is there is no valid Python file to ‘build’ (or, in this case just run).

That should do it. But now, seriously, as monobotsoft said, do yourself a big favor and do a good bit of the tutorial in the Python doc first.
Job 1 is: Learn some Python. THEN you mess with advanced tools that only complicate things and distract you from the main mission.
I would seriously suggest just using the “Idle” app that should have come with your Python install. It’s designed for learning. Get your basics down first, then come to ST, cuz you’re gonna need 'em. :smiley:

Dave

3 Likes

#5

[quote=“oldwarhorse”]Lighthammer,
Welcome! First of all, you need to SAVE your code file with the “.py” extension. Then, on the ‘Tools/Build System’ menu, make sure your build system is set to either ‘auto’ or ‘Python’. What that message is telling you is there is no valid Python file to ‘build’ (or, in this case just run).

That should do it. But now, seriously, as monobotsoft said, do yourself a big favor and do a good bit of the tutorial in the Python doc first.
Job 1 is: Learn some Python. THEN you mess with advanced tools that only complicate things and distract you from the main mission.
I would seriously suggest just using the “Idle” app that should have come with your Python install. It’s designed for learning. Get your basics down first, then come to ST, cuz you’re gonna need 'em. :smiley:

Dave[/quote]

I did follow a tutorial, but apparently it must have been for Python 2 then. I think I got it to work, a CMD window flashes real quick with something I think is “Hello, world!”.

This tutorial you’re talking of, where can I find it? I launched the IDLE (Python GUI) program, I’m guessing that’s what you mean by using the “idle” app.
Any help is much appreciated!

0 Likes

#6

I think your problem is that python is not in your path … to test it simply type " python " (without the quotes) in a cmd terminal … if the interpreter shows means that its correctly in your path … else you have to add it to you windows paths, how? --> stackoverflow.com/questions/6318 … -windows-7

just change the python27 for your python3 path and voila!

0 Likes

#7

i have a solution please mail me :slight_smile:

0 Likes

#8

upiyush11@gmail.com

0 Likes

#9

just before you execute the program first save that file

1 Like

#10

Please make sure that you’ve saved the file with ‘.py’ extension.

2 Likes

#11

mannnn this work for me. Ty this is simple but make me confuse for quite a while. Once again thx

0 Likes

#12

i was getting the same error in pycharm…
after watching many vids and reading many sites , when i couldn’t solve this , suddenly i remembered that after installing pycharm
-when i first opened a new file - i got a main file attached to it .

  • but i thought that is just some random thing do i deleted it and opened a new file.

    moving towards it’s solution-
    1- you can try reinstalling it completly .
    2-go on search option in pycharm (top right )
  • type history
    -click on (show local history)
  • there you will find all history that you may have deleted the main file and all
  • there just right click on main.py and select (revert)
  • then select the main file right click and make a new python file and run it …
    this definitely worked for me
0 Likes

#13

Did you build new system for your Sublime Text? If not, Tools -->Buid System --> New Buid System and delete all you see and paste this into then save it in the default folder which choose by Sublime Text. Then you can run shell by CMD + B (Mac) or Ctrl +B (windows)

{
“cmd”: ["/Library/Frameworks/Python.framework/Versions/3.8/bin/python3", “-u”, “$file”],
}

1 Like

#14

Hi! Thank you so much for your helpful information))
It helped me, also))

0 Likes

#16

That got me for a while, forgot to save the file as a “.py” so it would execute the program. everything worked fine after that.

0 Likes

#17

I looked and looked and looked… This was the only thing that helped me. Thank you so much!!!

0 Likes