Reputation: 6726
How does one change Windows 8 codepage in Python 3 Spyder console from cp1252 to utf-8?
The code page apparently is cp1252 as evidenced with
import locale
locale.getpreferredencoding()
This means that it is difficult to print non-ascii characters with 'print' as an exception is raised (UnicodeEncodeError
).
One possible solution is with the .encode method and its 'errors' argument.
u'\x9d'.encode('cp1252', errors='replace')
But why isn't there an (or where is the) option to change the console encoding to utf-8. I was expecting an option in the 'Preferences'.
Another solution is to execute the python file outside Spyder with like:
chcp 65001
c:\path_to_python\python.exe the_script.py
This works but lacks the integratedness of Spyder.
I tried to make a batch file with
chcp 65001
c:\path_to_python\python.exe
And set that to "use the following Python interpreter" in "Advanced settings", but Spyder would not allow it - at least the way I tried it.
I neither could make another workaround working by making a batch script with:
chcp 65001
c\:path_to_spyder\Spyder.exe
Upvotes: 0
Views: 1001
Reputation: 34156
(Spyder dev here) This will be fixed in our next release (i.e. version 2.3.2). Both input and output in the console will be treated as unicode from that release onwards, for Python 3 and Python 2 as well.
Upvotes: 1