Home>Article>Development Tools> What are the solutions to garbled characters when running python code in vscode terminal?

What are the solutions to garbled characters when running python code in vscode terminal?

王林
王林 Original
2019-11-14 15:54:11 3289browse

What are the solutions to garbled characters when running python code in vscode terminal?

1. Add system global variables

Take the windows system as an example, add system variables:

PYTHONIOENCODING=UTF8

2. Modify the VSC configuration file

Press the F1 key to bring up the console, enter task, select task: configure task runner, open the tasks.json file, and add the following information:

"options": { "env":{ "PYTHONIOENCODING": "UTF-8" } }

3. Change the encoding in the code

Add the following code to each python file that requires Chinese:

import io import sys #改变标准输出的默认编码 sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='utf8')

Recommended tutorial:vscode tutorial

The above is the detailed content of What are the solutions to garbled characters when running python code in vscode terminal?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn