vscode runs python program and outputs garbled code

王林
Release: 2020-03-14 11:48:05
Original
5662 people have browsed it

vscode runs python program and outputs garbled code

If you run the python code directly like this, print will appear. The Chinese printed out is garbled. There are three ways to solve this problem:

1. Add system global variables

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

PYTHONIOENCODING=UTF8
Copy after login

Restart vscode.

(Learning video recommendation:java video tutorial)

2. Modify the VSC configuration file

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

"options": { "env":{ "PYTHONIOENCODING": "UTF-8" } }
Copy after login

Restart vscode.

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')
Copy after login

Recommended related tutorials:vscode tutorial

The above is the detailed content of vscode runs python program and outputs garbled code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!