@@ -605,6 +605,50 @@ existed)::
605
605
606
606
C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Python 3.7
607
607
608
+ .. _win-utf8-mode :
609
+
610
+ UTF-8 mode
611
+ ==========
612
+
613
+ .. versionadded :: 3.7
614
+
615
+ Windows still uses legacy encodings for the system encoding (the ANSI Code
616
+ Page). Python uses it for the default encoding of text files (e.g.
617
+ :func: `locale.getpreferredencoding `).
618
+
619
+ This may cause issues because UTF-8 is widely used on the internet
620
+ and most Unix systems, including WSL (Windows Subsystem for Linux).
621
+
622
+ You can use UTF-8 mode to change the default text encoding to UTF-8.
623
+ You can enable UTF-8 mode via the ``-X utf8 `` command line option, or
624
+ the ``PYTHONUTF8=1 `` environment variable. See :envvar: `PYTHONUTF8 ` for
625
+ enabling UTF-8 mode, and :ref: `setting-envvars ` for how to modify
626
+ environment variables.
627
+
628
+ When UTF-8 mode is enabled:
629
+
630
+ * :func: `locale.getpreferredencoding ` returns ``'UTF-8' `` instead of
631
+ the system encoding. This function is used for the default text
632
+ encoding in many places, including :func: `open `, :class: `Popen `,
633
+ :meth: `Path.read_text `, etc.
634
+ * :data: `sys.stdin `, :data: `sys.stdout `, and :data: `sys.stderr `
635
+ all use UTF-8 as their text encoding.
636
+ * You can still use the system encoding via the "mbcs" codec.
637
+
638
+ Note that adding ``PYTHONUTF8=1 `` to the default environment variables
639
+ will affect all Python 3.7+ applications on your system.
640
+ If you have any Python 3.7+ applications which rely on the legacy
641
+ system encoding, it is recommended to set the environment variable
642
+ temporarily or use the ``-X utf8 `` command line option.
643
+
644
+ .. note ::
645
+ Even when UTF-8 mode is disabled, Python uses UTF-8 by default
646
+ on Windows for:
647
+
648
+ * Console I/O including standard I/O (see :pep: `528 ` for details).
649
+ * The filesystem encoding (see :pep: `529 ` for details).
650
+
651
+
608
652
.. _launcher :
609
653
610
654
Python Launcher for Windows
0 commit comments