Configure Python in Sublime Text: Fix Encoding Errors & Run Scripts with Ctrl+B
This tutorial walks through configuring the Python interpreter in Sublime Text by editing the Python.sublime-build file to add the Python path and UTF-8/GBK encoding, resolving decode errors and enabling script execution via Ctrl+B or the Build menu.
Problem: Ctrl+B Does Nothing Without a Configured Interpreter
A beginner asked why pressing Ctrl+B in Sublime Text produced no output when trying to run a Python script. The cause was a missing Python interpreter configuration — Sublime Text does not know which python.exe to invoke or how to handle non-ASCII output.
Step-by-Step Configuration
Open Preferences → Browse Packages… — This opens the Sublime Text packages directory.
Locate the Python folder and open Python.sublime-build in Sublime Text.
Edit the build file — The original content is minimal. Two key changes are required:
Add the path pointing to your Python installation (e.g., "path": "C:\\Python34").
Add an encoding field ( utf-8, gbk, or cp936) to prevent [Decode error - output not utf-8] when the script prints non-English characters.
Save with Ctrl+S .
Select the build system — Go to Tools → Build System → Python.
Run a Python file — Press Ctrl+B or choose Tools → Build. Output appears in the bottom panel.
Modified Python.sublime-build Example
{
"cmd": ["python.exe", "-u", "$file"],
"path": "C:\\Python34",
"file_regex": "^[ ]*File\"(...*?)\", line ([0-9]*)",
"encoding": "gbk",
"selector": "source.python"
}The encoding field is critical: without it, any non-English output triggers a decode error. The author notes that utf-8, gbk, or cp936 all work; try each if one fails.
Verification
After configuration, opening any .py file and pressing Ctrl+B runs the script and shows output in Sublime Text's bottom output panel. The same steps apply to both Sublime Text 2 and Sublime Text 3.
Reference
Original CSDN article: https://blog.csdn.net/zz153417230/article/details/78935265
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
