sublime text2 python 错误消息/usr/bin/python:在''中找不到'__main__'模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14330411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sublime text2 python error message /usr/bin/python: can't find '__main__' module in ''
提问by user1959940
I installed sublime text 2 to OSX 10.8.2. In my Mac, python 2.7.3 is installed.
我将 sublime text 2 安装到 OSX 10.8.2。在我的 Mac 中,安装了 python 2.7.3。
In sublime text2, I just type
在 sublime text2 中,我只输入
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?
我该如何解决?
回答by scarecrow
I got the same error as I didn't save the script before executing it. Check to see if you have saved it!
我遇到了同样的错误,因为我在执行之前没有保存脚本。检查您是否已保存它!
回答by rich tier
did you add the shebang to the top of the file?
您是否将shebang添加到文件顶部?
#!/usr/bin/python
回答by Andy Chase
Note to anyone else:
给其他人的注意:
If you have a directory like so, you can add a __main__.pyfile to tell the interpreter what to execute if you call the module directly.
如果你有一个这样的目录,你可以添加一个__main__.py文件来告诉解释器如果你直接调用模块要执行什么。
my_module
|
| __init__.py
| my_cool_file.py # print "Hello World"
| __main__.py # import my_cool_file
$ python my_module # Hello World
$ python my_module # Hello World
回答by gonzalez_najera
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).
您需要使用“.py”扩展名保存您的代码文件。然后,在“工具/构建系统”菜单上,确保您的构建系统设置为“自动”或“Python”。该消息告诉您没有有效的 Python 文件要“构建”(或者,在本例中只是运行)。
回答by George Sariev
Don't run with a space between the directory and the filename:
不要在目录和文件名之间使用空格运行:
python /root/Desktop/1 hello.py
Use a /instead:
使用 a/代替:
python /root/Desktop/1/hello.py
回答by Strong Lee
Save the .py files before you build in sublime.Such as save the file on desktop or other document.
在 sublime 中构建之前保存 .py 文件。例如将文件保存在桌面或其他文档中。
回答by Mushfiqur Rahman
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.
确保您没有单击“运行”选项卡中的“未命名运行”。您必须单击“运行”。或者只需单击绿色快捷按钮。
回答by Greendaddy
First save your program file type as "example.py then run your code its working fine.
首先将您的程序文件类型保存为“example.py,然后运行您的代码,使其工作正常。
回答by epadilla.12
You get that error because you haven't saved your file, save it for example "holamundo.py" then run it Ctrl+ B
你得到那个错误是因为你没有保存你的文件,保存它例如“holamundo.py”然后运行它Ctrl+B
回答by juuko daniel
The problem: The format of the file as to how it is saved.
Use a proper text editor and save it with the .pyextension
and run it in terminal.
问题:文件的格式与保存方式有关。使用适当的文本编辑器并将其与.py扩展名一起保存并在终端中运行。
eg: file name should be saved as `example.py`
run
python example

