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???
-
1Possible duplicate of [Python3.4 on Sublime Text 3](https://stackoverflow.com/questions/23257984/python3-4-on-sublime-text-3) – Brian J Sep 19 '17 at 20:35
8 Answers
Tools->Build System->Python or Ctrl+B

- 523
- 4
- 9
-
At the start of a new session: Tools->Build System->Python Every time you want to run the code after that: Ctrl + B – grego Feb 03 '21 at 22:14
Need to install package to run python from sublime Python + Sublime

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

- 11
- 3
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.

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

- 899
- 8
- 13
If you need non-interactive Build System, just follow the Official Guide.
If you plan to run code that contains something like input(), or you have any other way of interacting with your program you would need additional setup - Plugin + simple config.
The steps of having proper/full build system are:
- Install "Package Control":
Win/Linux: ctrl+shift+p, Mac: cmd+shift+p ▶ Type: Install Package Control ▶ ENTER
- Install Terminus via Package Control:
Win/Linux: ctrl+shift+p, Mac: cmd+shift+p ▶ Type: Package Control: Install Package ▶ ENTER ▶ Type: Terminus ▶ ENTER
- Create Build System for Python
Tools ▶ Build System ▶ New Build System… menu item or the Build: New Build System ▶ Paste one of the following sections and edit respectively.
For Windows, obviously you should change the path to your Python:
{
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"shell_cmd": "D:\\.python_venvs\\general_python\\Scripts\\python.exe -u \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"variants":
[
{
"name": "Syntax Check",
"shell_cmd": "D:\\.python_venvs\\general_python\\Scripts\\python.exe -m py_compile \"${file}\"",
}
]
}
For Mac/Linux, do not forget to change the path to your Python.:
{
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"shell_cmd": "/home/<user>/.python_venvs/general_python/Scripts/python -u \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"variants":
[
{
"name": "Syntax Check",
"shell_cmd": "/home/<user>/.python_venvs/general_python/Scripts/python -m py_compile \"${file}\"",
}
]
}
- Name the file e.g: Python Custom.sublime-build
- Select the newly created Build System:
Tools ▶ Build System ▶ Python Custom 6. Execute your code: Ctrl/CMD + B

- 146
- 1
- 4
@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
Delete the existing code and paste the code 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"
}
Then change the file location to where your python.exe file location is, in the above code
"C:\\Users\\Programs\\Python\\Python37\\python.exe"
Instead of the code lines of my file location path

- 48
- 6

- 1,135
- 10
- 21