Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sublime text2 python error message /usr/bin/python: can't find '__main__' module in ''

Tags:

python

I installed sublime text 2 to OSX 10.8.2. In my Mac, python 2.7.3 is installed.

In sublime text2, I just type

print 'Hello'

but error occurred like below.

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

How can I fix it?

like image 885
user1959940 Avatar asked Jan 15 '13 02:01

user1959940


3 Answers

I got the same error as I didn't save the script before executing it. Check to see if you have saved it!

like image 142
scarecrow Avatar answered Oct 24 '22 02:10

scarecrow


Note to anyone else:

If you have a directory like so, you can add a __main__.py file to tell the interpreter what to execute 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

like image 45
Andy Chase Avatar answered Oct 24 '22 02:10

Andy Chase


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).

like image 12
gonzalez_najera Avatar answered Oct 24 '22 01:10

gonzalez_najera