--Start with python -X utf8
--If that doesn't work, set the environment variable and set the variable name PYTHONIOENCODING
and the value ʻutf-8`.
"This article is written for people who use python3.8.0-python3.8.2 from windows. I don't know about python3.7 or earlier or newer versions than python3.8.2. " I dare to declare it like this.
Until you get to this article
http.server
or something, for examplesys.stdout = io.TextIOWrapper (sys.stdout.buffer, encoding ='utf-8')
and buffer
does not exist (in sys.stdout
)".Isn't it?
Apparently
** sys.stdout.buffer
seems to be deprecated from 3.8 ** (?).
on that evidence,
If you ask people who work this way, they will say 3.7 or earlier, and if you ask people who fail this way, they will say 3.8. (It may be a coincidence because I haven't investigated it properly. I'm sorry if that is the case.)
It's confusing because the information older than 3.8 says "for 3.x" or "for 3." At the time when 3.6 and 3.7 were the latest, I didn't think that the specifications would change with 3.8, so it seems that it has become generalized. From now on, I would like you to say something like "for python3.0-3.7" instead of saying "for python3".
According to https://qiita.com/butada/items/33db39ced989c2ebf644, the standard output consists of shift_jis in windows10 and earlier.
Because of that, if you run python3.8.2 or earlier on windows, ** whatever the character code inside python, it will be automatically converted to shift_jis at the time of output **. An error occurs during this process.
(By the way, in python3 ~ 3.8.2, the str type character code is fixed to utf-8.
There was also a bulletin board that suggested " # coding: utf-8
", but this is the source encoding specification)
In python3.7-3.8.2, when you start python
from the console, you can start it in" UTF-8 mode "by adding the option -X utf8
.
Here, the imitation such as "automatically convert to shift_jis" is stopped.
・ By the way, if you want to use http.server, this is not enough.
Set the environment variable to the variable name PYTHONIOENCODING
and the value ʻutf-8`.