Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode - Output window says "UnicodeEncodeError" when I try to print unicode

I just started to use VSCode on some python scripts. When I try to print something like:

print('%s' % string.decode('utf-8'))

I get following error in output window:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 16-20: ordinal not in range(128)

I know it probably because the output stream is ascii only, but I can't find a place to change it... , either I missed it, or it just the way it is?

I'm using v0.10.8 on Win7 64bit.

Thanks in advance!

like image 683
neolei Avatar asked Jan 02 '26 05:01

neolei


1 Answers

I suffer the same problem, it's caused by the the plugin -- Code Runner.

Please check the discussions here:

  • UnicodeEncodeError
  • Output utf8 chars incorrect

It suggest to write these into VSCode setting file:

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

if, it doesn't work, you can use this (run the script in terminal):

{
    "code-runner.runInTerminal": true
}
like image 82
patiencing Avatar answered Jan 03 '26 19:01

patiencing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!