I'll have to check that out. It looks like it would work fine for my purposes since I normally run from virtual envs, but could be restrictive in that the user site-packages isn't added. I also found some other mentions of this: https://bugs.python.org/issue33053https://bugs.python.org/issue13475 One idea may be, when executing "python -m", check to see if the module is loaded from CWD, if so then have CWD added, but if the module is not loaded from CWD then not have it added.
-----Original Message----- From: Nick Timkovich firstname.lastname@example.org To: Brianvanderburg2 email@example.com Cc: firstname.lastname@example.org email@example.com Sent: Mon, Feb 24, 2020 2:52 pm Subject: Re: [Python-ideas] Control adding script path/CWD to sys.path
On Mon, Feb 24, 2020 at 11:51 AM Brianvanderburg2 via Python-ideas firstname.lastname@example.org wrote:
When running a python script directly, the directory of that script gets added to sys.path. When running as a module "python -m", it looks like an empty string gets added to sys.path, which appears to result in CWD being used.
Are you familiar with the -I option for "isolated mode"? https://docs.python.org/3/using/cmdline.html#id2
-I Run Python in isolated mode. This also implies -E and -s. In isolated mode sys.path contains neither the script’s directory nor the user’s site-packages directory. All PYTHON* environment variables are ignored, too. Further restrictions may be imposed to prevent the user from injecting malicious code. New in version 3.4.