


How to run the current Python file in a new terminal from Sublime Text?
To make the current Python file run through a new terminal window in Sublime Text, you need to create a custom build system: 1. Select Tools → Compile System → Create a New Compilation System, and paste the JSON configuration of the corresponding operating system; 2. Select the commands according to the operating system (macOS uses osascript to call Terminal or iTerm2, Linux uses gnome-terminal, etc., Windows uses start cmd or PowerShell); 3. Save as Python-Terminal.sublime-build and select the compilation system; 4. Press Ctrl B (or Cmd B) to run, the terminal will execute the script and keep it open to view the output, and finally complete the entire execution process.
To run the current Python file in a new terminal from Sublime Text, you need to customize a build system that opens a new terminal window and executes the Python script. Here's how to set it up depending on your operating system.

1. Create a Custom Build System
Go to Tools > Build System > New Build System… in Sublime Text. This will open a new file where you can define the build configuration.
For macOS (using Terminal.app or iTerm2)
{ "cmd": ["osascript", "-e", "tell app \"Terminal\" to do script \"python3 '$file'; read -p 'Press Enter to exit...'\""], "selector": "source.python", "shell": true, "working_dir": "$file_path" }
If you're using iTerm2 instead of Terminal, replace
"Terminal"
with"iTerm"
and adjust the command accordingly.
Example for iTerm2:
{ "cmd": ["osascript", "-e", "tell app \"iTerm\" to create window with default profile command \"python3 '$file'; read -p 'Press Enter to exit...'\""], "selector": "source.python", "shell": true, "working_dir": "$file_path" }
Save this as Python-Terminal.sublime-build
.

For Linux (using gnome-terminal or xterm)
{ "cmd": ["gnome-terminal", "--", "bash", "-c", "python3 '$file'; read -p 'Press Enter to exit...'"], "selector": "source.python", "shell": true, "working_dir": "$file_path" }
Replace
gnome-terminal
withxterm
orkonsole
if you're using a different terminal emulator.
Save this as Python-Terminal.sublime-build
.
For Windows (using Command Prompt or PowerShell)
Using Command Prompt:
{ "cmd": ["start", "cmd", "/k", "python", "$file"], "shell": true, "working_dir": "$file_path", "selector": "source.python" }
Using PowerShell:
{ "cmd": ["start", "powershell", "-NoExit", "-Command", "python '$file'"], "shell": true, "working_dir": "$file_path", "selector": "source.python" }
Save the file appropriately and choose the build system via Tools > Build System .
2. Use the Build System
After saving the .sublime-build
file:
- Select it from Tools > Build System .
- Press
Ctrl B
(orCmd B
on macOS) to run the current Python file in a new terminal window.
The script will execute, and the terminal will remain open (thanks to read
or /k
) so you can see the output.
Notes
- Make sure
python
orpython3
is in your system's PATH. - The
$file
variable expands to the full path of the current file. -
working_dir
ensures the script runs in the correct directory. - On macOS and Linux,
read -p
keeps the terminal open until you press Enter. - On Windows,
/k
does the same forcmd
.
Basically, just save the right build config for your OS, select it, and use Build
( Ctrl B
). It's not hard once set up, but small syntax errors in the JSON or command can break it — double-check the commas and quotes.
The above is the detailed content of How to run the current Python file in a new terminal from Sublime Text?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

ArtGPT
AI image generator for creative art from text prompts.

Stock Market GPT
AI powered investment research for smarter decisions

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Configure Git to use SublimeText as the difference comparison tool. You need to set gitconfig to specify sublime as the default diff tool and define the call command; 2. Install the command line tool to make subl available in the terminal, and configure gitdifftool.sublime.cmd to use subl-w--wait--diff"$LOCAL""$REMOTE" to open the difference file; 3. Use the gitdifftool command to view changes between temporary storage or submissions in SublimeText in a double column view; 4. This method depends on the --d of SublimeText4

EmmetisapluginforSublimeTextthatacceleratesHTMLandCSScodingthroughabbreviations.2.InstallitviaPackageControlbyopeningtheCommandPalette,selecting"InstallPackage,"searchingforEmmet,andinstallingit.3.Afterinstallation,useabbreviationsinHTMLfil

GitGutterdisplaysreal-timelinechangesinSublimeTextusingicons: foradded,~formodified,-fordeleted,▶/↺formovedlines;installviaPackageControl,ensureGitisinPATH,enablefeatureslikelivemodeoruntrackedfilemarkersinsettings,anduseright-clickcommandstonavigate

Answer: To configure the Java build system for SublimeText, you need to install JDK and create a custom build file. 1. Make sure that the JDK is installed and the environment variables are correct; 2. Build a new build system in Sublime and use a JSON configuration containing javac and java commands; 3. Save as Java.sublime-build; 4. Select the build system and compile and run with Ctrl B. The output and errors will be displayed in the bottom panel, suitable for small projects or learning.

SublimeText automatically highlights matching HTML or XML tag pairs, and puts the cursor on the tag to display; if it does not take effect, check whether the syntax settings are correct. 1. Tag highlighting is supported by default to ensure that the file syntax is HTML or XML. 2. Optionally install the BracketHighlighter plug-in to enhance the effect. After searching and installing through the command panel, you can get clearer icons and underline prompts. 3. Adjust the highlight style through preferences, such as modifying it to solid, outline or underscore, and confirm that the label type is enabled.

UseCtrl Alt Up/Downtoaddcursorsaboveorbelow.2.PressCtrl DtoselectwordinstancesonebyoneorCtrl Alt Gtoselectallatonce.3.HoldCtrlandclicktoplacemultiplecursorsmanually.4.UseShift Altanddragforcolumnselectiontoeditmultiplelinesvertically.Thesemethodsenab

SublimeTextbecomesportablebydownloadingthe.zipversion,extractingit,andcreatinga"Data"folderbesidesublime_text.exe;thisstoresallsettingslocally.Whenlaunched,SublimeTextdetectstheDatafolderautomaticallyandsavespackages,preferences,andcachewit

SelectLlinesNoseEdit → Sortlinestosortalphabetically (Atoz) Oredit → Sortlines (Reverse) forzta; optionally, addcustomKeyboardSviapurance → keybindingsforfasteraccess.
