2

Output in Visual Studio Code can't decode Cyrillic characters:

Visual Studio Code can't decode Cyrillic characters

The same code works fine in PyCharm:

The same code works fine in PyCharm

How do I quickly fix this issue? There must be some simple way.

Auto Guess Encoding in Settings doesn't work since it's for files, not the output.

Edit: the problem was the Code Runner extension in VSCode. Disabling it or running script in terminal does the job.

Anatoly
  • 69
  • 2
  • 6
  • https://github.com/microsoft/vscode/issues/3550#issuecomment-343491889? – GSerg Sep 07 '19 at 14:09
  • Sadly, they didn't really explain how to fix this what seems to be the simplest of issues to have. There must be some sort of checkbox in the settings that I can not find. – Anatoly Sep 07 '19 at 14:26
  • https://github.com/microsoft/vscode/issues/3550#issuecomment-341557752? – GSerg Sep 07 '19 at 14:28
  • 1
    Code page 1251 does have the required glyphs to display that string. But not to display �. So Python isn't reading the .py file correctly. Either because the file actually contains � or because Python guessed incorrectly at its encoding. You can change the .py file encoding to cp1251: https://stackoverflow.com/questions/30082741/change-the-encoding-of-a-file-in-visual-studio-code – Hans Passant Sep 07 '19 at 14:30
  • Well, as I said, the same file works fine in PyCharm and the output is displayed correctly there. So for PyCharm encoding any text in this file is not a problem.. – Anatoly Sep 07 '19 at 14:45
  • 1
    The output shown in the screenshot is from some third-party extension (Code Runner?). You might find further info in the extension's settings or documentation. – Álvaro González Sep 07 '19 at 16:13
  • Yes, that's it! The problem was the Code Runner. Apparently it can not process non-latin characters or something.. The code runs smoothly in the terminal, guess I'll have to get used to it now. Many thanks! – Anatoly Sep 07 '19 at 18:22

2 Answers2

1

You can configure 'Code Runner' plugin to run your code in the integrated terminal.

Try it:

  1. Open VSC Settings: Ctrl + ,
  2. Search: code runner run in terminal
  3. Click on checkbox.

Now your application with Cyrillic symbols run in Integred Terminal without encoding problems.

ill
  • 11
  • 2
0

The problem lies in the Code Runner encoding itself, since the text is displayed correctly in the terminal.

You can add into settings.json :

"code-runner.executorMap": {"python": "set PYTHONIOENCODING=utf8 && py -u"},