简体   繁体   English

在Sublime Text中构建Python

[英]Building Python in Sublime Text

I am unable to get a Python system to build on a friend's computer which runs Windows XP SP3 using Sublime Text 2. We reinstalled Python 2.7.3 and also Sublime Text 2 and still are having trouble with this. 我无法在朋友的计算机上构建Python系统,该计算机使用Sublime Text 2运行Windows XP SP3。我们重新安装了Python 2.7.3和Sublime Text 2,但仍然遇到问题。 Our Python.sublime-build field says: 我们的Python.sublime-build字段说:

{
    "cmd": ["C:\\Python27\\python.exe", "-u", "$(FULL_CURRENT_PATH)"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

When we try to build simple Python programs, such as: 当我们尝试构建简单的Python程序时,例如:

2 * 2

Sublime Text will not build the system, and will instead spit out: Sublime Text不会构建系统,而是吐出来:

C:\Python27\python.exe: can't find '__main__' module in ''
[Finished in 0.1s with exit code 1]

It would be wonderful if I could get some help with this. 如果我能得到一些帮助,那就太棒了。 Thank you so much whoever assists me with this! 非常感谢你帮助我的人!

I fixed this by saving my file as a .py file. 我通过将文件保存为.py文件来修复此问题。 I opened up a new file, added some code, and tried to build it, which gave me that error. 我打开了一个新文件,添加了一些代码,并尝试构建它,这给了我这个错误。 After saving as a .py file, I was able to build and run fine. 保存为.py文件后,我能够构建并运行正常。

You didn't save the file. 你没有保存文件。 You need to save the file like name_fila.py then you'll be able to run it 您需要像name_fila.py一样保存文件,然后您就可以运行它了

I used this for Python 3.4 and it works pretty good 我在Python 3.4中使用它,它的效果非常好

The current path you put seems to be the issue. 您放置的当前路径似乎是个问题。

"$(FULL_CURRENT_PATH)" --> "$file" "$(FULL_CURRENT_PATH)" - > "$file"

{ "cmd": ["C:\\\\Python34\\\\python.exe", "-u", "$file"], "file_regex": "^[ ]*File \\"(...*?)\\", line ([0-9]*)", "selector": "source.python" }

Alexandre 亚历山大

我认为你应该做一个__main__这样__name__ == '__main__'模块,然后尝试编译它...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM