How to Fix Chinese Garbled Text in Jupyter and VS Code: Simple Encoding Tricks
This article explains why Chinese characters appear as garbled text in Jupyter notebooks and VS Code, demonstrates the issue with screenshots, evaluates several Python code fixes, and ultimately provides a reliable solution by setting the console code page to UTF‑8.
1. Introduction
The author encountered a Chinese‑character garbling problem when running code in a Jupyter notebook and sought help in a Python community.
2. Problem Demonstration
Both screenshots below show the garbled output where Chinese text appears as unreadable symbols.
3. Solutions
Solution for Python 2.x – resetting the default encoding to UTF‑8:
import sys
stdi, stdo, stde = sys.stdin, sys.stdout, sys.stderr
reload(sys)
sys.setdefaultencoding('utf-8')
sys.stdin, sys.stdout, sys.stderr = stdi, stdo, stdeThis method works only under Python 2 and may still cause issues.
Attempt for Python 3.x – reloading the sys module:
import importlib, sys
importlib.reload(sys)The above did not resolve the garbling.
A blog post about VS Code Chinese‑character issues ( link ) highlighted the error “锟斤铐”. The effective fix is to set the console code page to UTF‑8 before launching Python:
chcp 65001Explanation of the “锟斤铐” gibberish: it occurs when text encoded in UTF‑8 is mistakenly read as GBK (or vice‑versa), leading to mis‑interpreted byte sequences.
4. Conclusion
The article walks through the garbled‑character issue, evaluates several code‑based attempts, and identifies the reliable “chcp 65001” workaround for VS Code, helping readers resolve similar encoding problems.
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.
