MacOS下搭建Python3构建系统及ST3构建配置运行报错求助
Fixing the "Run in cmd" Build Variant Error on macOS for Sublime Text 3
Got it, let's break down why your "Run in cmd" variant is throwing errors on macOS: that start cmd /c command is Windows-only—macOS doesn't recognize cmd or start at all, which is exactly what's causing the failure.
The Corrected macOS-Compatible Build System Config
Replace your existing build system code with this version tailored for macOS:
{ "shell_cmd": "python3 -u \"$file\"", "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python", "env": {"PYTHONIOENCODING": "utf-8"}, "variants": [ { "name": "Syntax Check", "shell_cmd": "python3 -m py_compile \"${file}\"" }, { "name": "Run in Terminal", "shell_cmd": "open -a Terminal.app \"python3 '${file}' && read -p 'Press Enter to exit...'\"" } ] }
Key Changes Explained
- Renamed the variant to "Run in Terminal" (more accurate for macOS)
- Swapped Windows-specific
start cmd /cwithopen -a Terminal.app, which launches macOS's native Terminal app - Added
&& read -p 'Press Enter to exit...'to keep the Terminal window open after your script finishes—no more missing output because the window closes instantly - Wrapped
${file}in single quotes to handle file paths with spaces correctly
How to Set This Up
- In Sublime Text 3, go to
Tools > Build System > New Build System... - Replace the default template content with the code above
- Save it as
Python3.sublime-build(make sure it saves to the defaultUserdirectory that pops up) - Select
Tools > Build System > Python3, then useTools > Build With...and pick "Run in Terminal" to test it out
This should fix the error and let you run your Python scripts in a native macOS Terminal window directly from Sublime Text.
内容的提问来源于stack exchange,提问作者Eugenia M
相关产品推荐
相关产品推荐

