[Visual Studio Code] [Python] [Windows] Support for garbled Japanese characters in Python in VS Code task / debug output

I was in trouble because the Japanese output during debugging was garbled, so make a note of how to deal with it. It seems that the terminal used for output is not UTF-8.

environment

VSCode Extensions:

1. Japanese characters in task output are garbled

TODO: Unsolved (seems to be listed in Issue)

Tasks should support specifying the output encoding · Issue #3550 · Microsoft/vscode

I also saw a comment that could be solved by sending the output of the task to the terminal. (Unverified)

Run build task fails · Issue #20152 · Microsoft/vscode

[Addition] Change the standard output setting of Python

It was also possible to respond by adding the following settings

Change the standard output encoding


import sys
import io

sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')

TODO list when encountering UnicodeDecodeError in Python3 --Qiita

2. Japanese characters in debug output are garbled

It is assumed that launch.json has the following settings. (Generated by pressing the debug gear mark in the initial state)

launch.json


        {
            "name": "Integrated Terminal/Console",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config.python.pythonPath}",
            "program": "${file}",
            "cwd": "null",
            "console": "integratedTerminal",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit"
            ]
        },

1.png

In Debug, select ʻIntegrated Terminal / Console`. Execute it once, and execute the following on the displayed terminal.

UTF terminal-Fixed to 8


Terminal> chcp 65001

There should be no problem with the subsequent Japanese output. (The terminal will be reused, but if you close it, please try again)

reference

Visual Studio Code --Visual Studio Code OUTPUT is garbled (42828) | teratail

Recommended Posts

[Visual Studio Code] [Python] [Windows] Support for garbled Japanese characters in Python in VS Code task / debug output
Settings for Python coding in Visual Studio Code
Japanese output when dealing with python in visual studio
Create a Python environment for professionals in VS Code on Windows
Windows Qt5.4 Python3.4 QProcess Japanese garbled characters
[Visual Studio Code] [Python] Tasks.json + problemMatcher settings for Python
Japanese output in Python
VS Code settings for developing in Python with completion
Make Visual Studio Code autocomplete for python external libraries
Python development environment with Windows + Anaconda3 + Visual Studio Code
Python development environment with Windows + Python + PipEnv + Visual Studio Code
AWS SDK for Python (Boto3) development in Visual Studio 2017
Expose settings.json for efficient Python coding in VS Code
Execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people) Debugging
Execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people) Environment construction
Python with VS Code (Windows 10)
How to debug the Python standard library in Visual Studio
Eliminate garbled Japanese characters in Python library matplotlib and NetworkX
Debug Python with VS Code
Do something like a Python interpreter in Visual Studio Code
Install python and Visual Studio Code on windows10 (April 2020 version)
Python development in Visual Studio 2017
Build Python3 for Windows 10 on ARM with Visual Studio 2019 (x86) on Windows 10 on ARM
Python development in Visual Studio
Bash, Python, Javascript, code command, etc. in Visual Studio Code on Mac
About the procedure for linking Visual Studio Code for Windows and WSL
A memo for those who use Python in Visual Studio (me)
Build an environment to execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people)
Use Jupyter Notebook with Visual Studio Code on Windows 10 + Python + Poetry + pyenv-win
Create a Python development environment on Windows (Visual Studio Code remote WSL).
Eliminate garbled Japanese characters in matplotlib graphs in Cloud Pak for Data Notebook
A python script for Mac that zips without garbled characters on Windows
Installation of Visual studio code and installation of python
Python Tools for Visual Studio Installation Guide
Python garbled in Windows + Git Bash environment
Run Python in C ++ on Visual Studio 2017
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
Highlight Python user function calls in Visual Studio Code (vscode) Default Dark + theme
Steps to put dlib in Python Tools for Visual Studio and have fun
I customized it with Visual Studio Code (mainly for python), so I will summarize it
Run Python YOLOv3 in C ++ on Visual Studio 2017
Python (Windows 10) Virtual Environment / Package with VS Code
Debug with VS Code using boost python numpy
Django with Python Tools 2.2 for Visual Studio (PTVS 2.2)
Create an image with characters in python (Japanese)
Use Python in Anaconda environment with VS Code
Fix garbled characters when handling Japanese in Requests
Japanese support for Jupyter PDF output (December 2020 version)
[Python] Read Japanese csv with pandas without garbled characters (and extract columns written in Japanese)
What to do if Python IntelliSense is not displayed in VS Code on Windows