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

Python

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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

Solution 2 - Python

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

Solution 3 - Python

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

Solution 4 - Python

First save your program file type as "example.py then run your code its working fine.

Solution 5 - Python

did you add the shebang to the top of the file?

#!/usr/bin/python

Solution 6 - Python

Don't run with a space between the directory and the filename:

python /root/Desktop/1 hello.py

Use a / instead:

python /root/Desktop/1/hello.py

Solution 7 - Python

The problem: The format of the file as to how it is saved. Use a proper text editor and save it with the .py extension and run it in terminal.

eg: file name should be saved as `example.py`
run
python example

Solution 8 - Python

Save the .py files before you build in sublime.Such as save the file on desktop or other document.

Solution 9 - Python

Make sure that you aren't clicking on "Run unnamed" from 'run' tab. You must click on "run ". Or just click the green shortcut button.

Solution 10 - Python

Edit the configuration and then in the box: Script path, select your .py file!

Solution 11 - Python

You get that error because you haven't saved your file, save it for example "holamundo.py" then run it Ctrl + B

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1959940View Question on Stackoverflow
Solution 1 - PythonscarecrowView Answer on Stackoverflow
Solution 2 - PythonAndy ChaseView Answer on Stackoverflow
Solution 3 - Pythongonzalez_najeraView Answer on Stackoverflow
Solution 4 - PythonGreendaddyView Answer on Stackoverflow
Solution 5 - PythonDjango DoctorView Answer on Stackoverflow
Solution 6 - PythonGeorge SarievView Answer on Stackoverflow
Solution 7 - Pythonjuuko danielView Answer on Stackoverflow
Solution 8 - PythonStrong LeeView Answer on Stackoverflow
Solution 9 - PythonMushfiqur RahmanView Answer on Stackoverflow
Solution 10 - PythonCoder GuyView Answer on Stackoverflow
Solution 11 - Pythonepadilla.12View Answer on Stackoverflow