Set Python environmental variables for IDLE?

Viewed 541

How to set to native Python env vars for IDLE in Windows? Like PYTHONIOENCODING, PYTHONLEGACYWINDOWSSTDIO and so on.

A quick search here didn't find anything relevant except this, but this question is related only to Linux.

Web-search also didn't bring useful results, I tried follow this guide, which simply says one should define Windows user env variables in Control Panel, but this doesn't work.

When I do in IDLE

import os
print(os.environ['PYTHONSTARTUP'])

it throws:

Traceback (most recent call last): File "<pyshell#1>", line 1, in print(os.environ['PYTHONSTARTUP']) File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\os.py", line 679, in getitem raise KeyError(key) from None KeyError: 'PYTHONSTARTUP'

Should it work for IDLE and I just check it wrong or this is valid only for commandline Python?

1 Answers

Setting environmental variables has nothing to do with IDLE. Doing so with the Windows 10 Setting dialog is beyond the scope of stackoverflow. (And since one can only open the dialog for an admin account, I do not know how to permanently set environmental vars for a non-admin account.)

Setting environment var with os.environ is a python question, but I believe it is only temporary. In any case, running code with os.environ from IDLE is the same as running it directly with Python. When 'PYTHONSTARTUP' is not set, your example code fails the same way in a Windows console.

Related