I guess I'm confused if you want (e.g.) `python json.py` to do something but not `python -m json` to call the same file (a different way), given you're in the directory.

nick@lappy386:~/Code$ echo "{}" | python -m json.tool
nick@lappy386:~/Code$ touch json.py
nick@lappy386:~/Code$ echo "{}" | python -m json.tool
.../bin/python: Error while finding module specification for 'json.tool' (ModuleNotFoundError: __path__ attribute not found on 'json' while trying to find 'json.tool')
nick@lappy386:~/Code$ echo "{}" | python -I -m json.tool

Isolated mode effectively ignores the environment (variables and directory), so it will only use what's in that Python's site-packages (non-user, but could be a virtualenv)

If you want the local path to not be on `sys.path` for a *script-like* call, you could do `python -I myscript.py`, but `-m mypkg` is I think indistinguishable from trying to `import mypkg`, so it needs to be discoverable on `sys.path`...this feels like an A/B problem: what are you trying to do?

On Mon, Feb 24, 2020 at 3:35 PM <jdveiga@gmail.com> wrote:
Nick Timkovich wrote:

> > 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.

Oooh... Can you provide some examples on the use of -I?

I try to use along with -m (`python -I -m a.b`) and get this error: "python: Error while finding module specification for 'a.b' (ModuleNotFoundError: No module named 'a')".

On the other hand `python -m a.b -I` just passed -I as a script's CLI argument.

Of course, I get the expected results if run `python -I` on terminal.
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/QTZRM5QZI6DI7D43XVYX2GR75IX5SUFX/
Code of Conduct: http://python.org/psf/codeofconduct/