![](https://secure.gravatar.com/avatar/15b1cd41a4c23e7dc10893777afb4281.jpg?s=120&d=mm&r=g)
The use case for -P still uses environment variables like PYTHONWARNINGS or PYTHONUTF8. That's why -I (isolated) cannot be used. If there is an use case for a ._pth file importing the site module, maybe a different option can be added, no? Adding -P doesn't prevent that. But it seems like use cases are different enough to justify two options, no? Victor On Tue, Apr 26, 2022 at 11:52 PM Victor Stinner <vstinner@python.org> wrote:
The only purpose of proposed -P option is to "not add sys.path[0]". There are use cases which only need that.
Victor
On Tue, Apr 26, 2022 at 8:37 PM Steve Dower <steve.dower@python.org> wrote:
On 4/26/2022 10:46 AM, Victor Stinner wrote:
I propose adding a -P option to Python command line interface to "not add sys.path[0]": https://github.com/python/cpython/pull/31542
See the documentation in the PR for the exact behavior of this option. I prefer to add an environment variable, only pass the option explicitly on the command line.
Another viable option might be to add an option to imply "import site", which would work together with -I to: * ignore environment variables (-E/-I) * omit implicit CWD imports (-I) * still process .pth files (-?) * still include site-packages and user site-packages in sys.path (-?)
It seems likely that the proposed -P would almost always be used with -E, since if you can't control CWD then you presumably can't control environment variables either.
The existing ._pth functionality starts by implying -I, and allows "import site" in the file to explicitly include site. A command-line option matching this behaviour would be consistent. There's also already configuration in our structures for import site, so there'd be no need to add new fields to public APIs for the option.
The biggest issue I see is that the obvious command line options for "import site" are already used to imply "do not import site". But then, -P isn't obvious either. Maybe an -X option would suffice?
Cheers, Steve
-- Night gathers, and now my watch begins. It shall not end until my death.
-- Night gathers, and now my watch begins. It shall not end until my death.