Sublime text2 python / usr / bin / python error message: cannot find module '__main__' in ''

I installed sublime text 2 on OSX 10.8.2. My Mac has python 2.7.3 installed.

In sublime text2 I just type

print 'Hello' 

but an error occurred as shown below.

 /usr/bin/python: can't find '__main__' module in '' [Finished in 0.2s with exit code 1] 

How can i fix this?

+43
python
Jan 15 '13 at 2:51
source share
5 answers

I got the same error as I did not save the script before executing it. Check if you saved it.

+63
Jan 15 '13 at 3:09
source share

Note to anyone else:

If you have such a directory, you can add the __main__.py file to tell the interpreter what to do if you call the module directly.

 my_module | | __init__.py | my_cool_file.py # print "Hello World" | __main__.py # import my_cool_file 

$ python my_module # Hello World

+32
Jun 14 '13 at 3:37 on
source share

You need to SAVE your code file with the extension ".py". Then, in the Tools / Build menu, make sure your build system is set to Auto or Python. What this message tells you is that there is no valid Python file to “build” (or, in this case, just start).

+10
Apr 21 '14 at 4:08
source share

Have you added shebang to the top of the file?

 #!/usr/bin/python 
+2
Jan 15 '13 at 12:24
source share

Do not run a space between the directory and the file name:

 python /root/Desktop/1 hello.py 

Use / : instead

 python /root/Desktop/1/hello.py 
-one
May 05 '15 at 3:20
source share



All Articles