On 2/9/21, Inada Naoki <songofaca...@gmail.com> wrote:
> On Tue, Feb 9, 2021 at 7:42 PM M.-A. Lemburg <m...@egenix.com> wrote:
>
> But it affects to all Python installs. Can teachers recommend to set
> PYTHONUTF8 environment variable for students?

Users can simply create a shortcut that targets `cmd /k set
PYTHONUTF8=1`. Optionally change the shortcut's "start in" directory
to the desired working directory.

>> Here's a good blog post about setting env vars on Windows:
>>
>> https://www.dowdandassociates.com/blog/content/
>> howto-set-an-environment-variable-in-windows-command-line-and-registry/

Command-line modification of the persistent environment is rarely
required. Using setx.exe is okay for setting simple variables in CMD
[1], such as `setx PYTHONUTF8 1`, combined with `set PYTHONUTF8=1` for
the current shell.

To do this in the GUI in Windows 10, click on the start button (or tap
the WIN key) to show the start menu; type "environ"; and click on
"Edit environment variables for your account". In the window that
opens, click the "New" button; type "PYTHONUTF8" as the name and "1"
(without quotes) as the value. Click the "OK" button on the dialog,
and then click the "OK" button on the editor window.

To test the value, assuming you have the py launcher installed, press
WIN+R to open the run dialog. Type "py", and in the Python shell
confirm that executing `import locale; locale.getpreferredencoding()`
returns 'UTF-8'.

---
[1] I would feel remiss in discussing "setx.exe" without warning about
naively trying to modify PATH. For example, DO NOT execute a command
like `setx.exe PATH "C:\Program Files\Python39;%PATH%"`. This is wrong
because it sets the current PATH value, including the system part, as
the user "Path" value, truncated to 1024 characters, and without the
original dependence on system variables and independent (REG_SZ) user
variables. Properly modifying the persistent "Path" from CMD is
difficult and requires careful use of both reg.exe and setx.exe. It's
easier in PowerShell. It's far easier to use the GUI editor, which in
Windows 10 even provides an exploded list view that makes it simple to
add/remove directories and move them up and down in the list.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WOTADHRBJRTMERYNVUOW4LMW3CIKHTDQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to