-->

How to run python code in Sublime Text 3?

2020-07-25 09:15发布

问题:

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???

回答1:

Tools->Build System->Python or Ctrl+B



回答2:

Need to install package to run python from sublime Python + Sublime



回答3:

Try Anaconda plugin which will help you to run python on sublime

Setup Sublime for python



回答4:

You can use this package in sublime text: https://packagecontrol.io/packages/Terminal to open a terminal at the specific file or folder.



回答5:

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

  • One way: https://github.com/Wilhox/Integrated-builder.git



回答6:

@Thayakorn Rakwetpakorn's answer is correct

Ctrl+ B, and also make sure to have saved the file as hello.py or something before trying to run it

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

"C:\\Users\\Programs\\Python\\Python37\\python.exe"

Instead of the code lines of my file location path



回答7:

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.

{
  "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.