When running this code with python myscript.py from Windows console cmd.exe (i.e. outside of Sublime Text), it works:
# co
I have found a possible fix: add the encoding parameter in the Python.sublime-build file:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "cp1252",
...
Note: "encoding": "latin1" seems to work as well, but - I don't know why - "encoding": "utf8" does not work, even if the .py file is UTF8, even if Python 3 uses UTF8, etc. Mystery!
Edit: This works now:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf8",
"env": {"PYTHONIOENCODING": "utf-8", "LANG": "en_US.UTF-8"},
}
Linked topic:
Setting the correct encoding when piping stdout in Python and this answer in particular
How to change the preferred encoding in Sublime Text 3 for MacOS for the env trick.