如何在 Sublime Text 3 中运行 python 代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46306331/
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
How to run python code in Sublime Text 3?
提问by Jonah Johnson
So I'm trying to run python code from Sublime Text 3, but I'm not sure how. Even if it was only from the console, that would be fine. Anybody know how???
所以我试图从 Sublime Text 3 运行 python 代码,但我不确定如何。即使它只是来自控制台,那也没关系。有谁知道怎么做???
回答by Thayakorn Rakwetpakorn
Tools->Build System->Python or Ctrl+B
工具->构建系统->Python 或 Ctrl+B
回答by Dharmesh
Need to install package to run python from sublime Python + Sublime
需要安装包才能从 sublime Python + Sublime运行 python
回答by napster
回答by sikkis
You can use this package in sublime text: https://packagecontrol.io/packages/Terminalto open a terminal at the specific file or folder.
您可以在 sublime text 中使用此包:https: //packagecontrol.io/packages/Terminal在特定文件或文件夹中打开终端。
回答by Ville
Sublime Text 3 will run your python code inside the integrated console when you use Ctrl + B
if you want to run your code at own terminal, but still get some error information inside to integrated console, you need to build your own builder, or use plugins.
当您使用 Ctrl + B 时,Sublime Text 3 将在集成控制台中运行您的 Python 代码
如果您想在自己的终端上运行代码,但仍然在集成控制台中获取一些错误信息,则需要构建自己的构建器,或使用插件。
回答by Dulangi_Kanchana
@Thayakorn Rakwetpakorn's answer is correct
@Thayakorn Rakwetpakorn 的回答是正确的
Ctrl+ B, and also make sure to have saved the file as hello.py or something before trying to run it
Ctrl+ B,并确保在尝试运行之前将文件保存为 hello.py 或其他内容
If that doesnt work Tools->Build system -> New build system
如果这不起作用工具->构建系统->新构建系统
Comment the already existing code as i have shown below
评论已经存在的代码,如下所示
{
//"shell_cmd": "make"
"cmd": ["C:\Users\Programs\Python\Python37\python.exe","-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector': "source.python"
}
Type this set of code, and change the file location to where your python.exe file location is, in above code lines
键入这组代码,并将文件位置更改为您的 python.exe 文件位置,在上面的代码行中
"C:\Users\Programs\Python\Python37\python.exe"
Instead of the code lines of my file location path
而不是我的文件位置路径的代码行
回答by Manu S Pillai
This answer is for fellow googlers who want to run python scripts within their sublime. As other answers explains, all you need is a sublime build system, here after a bit of struggle I got it worked for Linux Systems.
这个答案适用于想要在他们的 sublime 中运行 python 脚本的谷歌员工。正如其他答案所解释的那样,您只需要一个崇高的构建系统,经过一番努力,我让它适用于 Linux 系统。
{
"cmd": ["gnome-terminal", "--", "/bin/bash", "-c", "python3 -u \"$file\" echo;echo;echo Press Enter to exit...;read"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
This is by far the simplest I believe. Hope it helps.
这是迄今为止我认为最简单的。希望能帮助到你。