You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 /c with open -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

  1. In Sublime Text 3, go to Tools > Build System > New Build System...
  2. Replace the default template content with the code above
  3. Save it as Python3.sublime-build (make sure it saves to the default User directory that pops up)
  4. Select Tools > Build System > Python3, then use Tools > 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:51:09