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