0

I've just uninstalled all languages on my Windows 10 except for English and set the system locale to English (US). python says that my preferred encoding is cp1252 which is quite the opposite of what I prefer (utf-8).

C:\Users\nope>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getpreferredencoding()
'cp1252'

How do I change my preferred encoding to utf-8? And most importantly where is python getting cp1252 from?

foxneSs
  • 2,259
  • 3
  • 18
  • 21
  • You can change this with the `chcp` command on the command line. There are issues with UTF-8 support in the Windows console. – Martijn Pieters Oct 29 '16 at 18:54
  • The better alternative is to upgrade to Python 3.6 where on Windows the default is UTF-8 now. – Martijn Pieters Oct 29 '16 at 19:01
  • @MartijnPieters The better alternative is to upgrade to an unreleased version of Python? – L3viathan Oct 29 '16 at 19:21
  • @MartijnPieters First of all, my question is not a duplicate of that question. My question is "Where does Python get the preferred encoding from?". Secondly, I've just installed Python 3.6 and my preferred encoding is still `cp1252`. – foxneSs Oct 29 '16 at 19:29
  • 1
    @foxneSs: see https://docs.python.org/3.6/whatsnew/3.6.html#pep-528; the *console encoding* is UTF-8. Windows still sets an ANSI codepage for the 'locale' regardless. The `getpreferredencoding()` function on Windows returns the second value from the tuple returned by the [`PyLocale_getdefaultlocale()` C function](https://hg.python.org/cpython/file/3.5/Modules/_localemodule.c#l284), where the `encoding` value comes from the Windows API [`GetACP()` function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd318070(v=vs.85).aspx). Python 3.6 heeds the warning there and uses Unicode APIs. – Martijn Pieters Oct 30 '16 at 09:56

0 Answers0