Fundamentals 4 min read

How to Fix Chinese Garbled Text in Jupyter Notebooks: A Step-by-Step Guide

This article explains why Chinese characters appear as garbled symbols in Jupyter notebooks, reviews several ineffective Python‑based fixes, and presents a simple Windows console command (chcp 65001) that reliably resolves the encoding issue.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Fix Chinese Garbled Text in Jupyter Notebooks: A Step-by-Step Guide

Introduction

In a Python community chat, the author encountered garbled Chinese characters when viewing a Jupyter notebook, while normal console output displayed correctly.

Problem Demonstration

The notebook shows unreadable characters instead of the expected Chinese text.

Attempted Fixes

First, a Python 2‑style solution was tried:

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, stde

This approach fails under Python 3.

Next, reloading the sys module with importlib.reload was attempted:

import importlib, sys
importlib.reload(sys)

It also did not resolve the issue.

Effective Solution

A contributor suggested setting the Windows console code page to UTF‑8 before launching the notebook:

chcp 65001

Running this command fixes the garbled output.

Why the Error Occurs

The “锟斤铐” characters are a typical symptom of reading UTF‑8 encoded text with a GBK decoder (or vice‑versa). Mismatched encodings cause the unreadable symbols.

Conclusion

The article summarizes the encoding problem, presents several failed attempts, and highlights the simple chcp 65001 fix, helping Python users resolve similar Unicode issues in Jupyter notebooks.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

encodingUnicodeJupyterchcp
Python Crawling & Data Mining
Written by

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!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.