How to know whether a script is executed by ParaView Python?

Is there a way to know at runtime if a Python file is executed from the ParaView environment (pvpython, pvbatch or from the Python shell of the GUI) or from a standard Python interpreter? I checked the environment variables with

$ pvpython
>>> import os
>>> from pprint import pprint
>>> pprint(os.environ._data)

but did not find anything that would indicate that.

if __name__ == '__main__'
# we’re in batch mode
else:
# we’re inside the GUI, a.k.a. ‘_vtkconsole_’

__name__ allows us to differentiate between batch mode and PV GUI mode, but even if __name__ == '__main__', the script could be executed from pvpython/pvbatch and from a standard Python interpreter. This latter is what I would like to know. I edited the post.

Can you import sys and inspect sys.argv[0] ot sys.executable?

Running as a command just prints the flag -c:

$ python3 -c "import sys; print(sys.argv[0])"
-c
$ pvpython -c "import sys; print(sys.argv[0])"
-c

Putting these commands into the file t.py gives back the file name:

$ python3 t.py
t.py
$ pvpython t.py
t.py

In interactive mode (REPL), there is nothing:

$ python3
>>> import sys; sys.argv[0]
''
$ pvpython
>>> import sys; sys.argv[0]
''

Try sys.executable

Running with pvpython returns …/bin/pvpython-real. Thank you!