Python 3.7 introduced the PYTHONUTF8 environment variable to enable UTF-8 encoding by default. How do I set this variable from within a Python program? (I can't find it in my operating system's list of environment variables.)
UTF-8 is one of the most commonly used encodings, and Python often defaults to using it.
To permanently modify the default environment variables, click Start and search for 'edit environment variables', or open System properties, Advanced system settings and click the Environment Variables button. In this dialog, you can add or modify User and System variables.
As a content author or developer, you should nowadays always choose the UTF-8 character encoding for your content or data. This Unicode encoding is a good choice because you can use a single character encoding to handle any character you are likely to need. This greatly simplifies things.
Usually you would specify this with a command line argument
python3.7 -X utf8
If you want to enable UTF-8 mode from environment variable:
export PYTHONUTF8=1 # linux / macOS
set PYTHONUTF8=1 # windows
It should be set before entering the Python runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With