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

**URL:** https://discourse.paraview.org/t/how-to-know-whether-a-script-is-executed-by-paraview-python/17610
**Category:** ParaView Support
**Tags:** python
**Created:** [June 10, 2026, 1:20pm UTC](https://discourse.paraview.org/t/how-to-know-whether-a-script-is-executed-by-paraview-python/17610 "2026-06-10T13:20:58Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![CsatiZoltan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/csatizoltan/32/6997_2.png) [@CsatiZoltan](https://discourse.paraview.org/u/CsatiZoltan)
#### Post date: [June 10, 2026, 1:20pm UTC](https://discourse.paraview.org/t/how-to-know-whether-a-script-is-executed-by-paraview-python/17610/1 "2026-06-10T13:20:58Z")

</div>

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](https://www.paraview.org/paraview-docs/latest/cxx/EnvironmentVariables.html) with

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

```

but did not find anything that would indicate that.

---

<div class="post-metadata">

### Author: ![jfavre](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jfavre](https://discourse.paraview.org/u/jfavre)
#### Post date: [June 10, 2026, 1:48pm UTC](https://discourse.paraview.org/t/how-to-know-whether-a-script-is-executed-by-paraview-python/17610/2 "2026-06-10T13:48:55Z")

</div>

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

---

<div class="post-metadata">

### Author: ![CsatiZoltan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/csatizoltan/32/6997_2.png) [@CsatiZoltan](https://discourse.paraview.org/u/CsatiZoltan)
#### Post date: [June 10, 2026, 1:57pm UTC](https://discourse.paraview.org/t/how-to-know-whether-a-script-is-executed-by-paraview-python/17610/3 "2026-06-10T13:57:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dcthomp](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dcthomp/32/20_2.png) [@dcthomp](https://discourse.paraview.org/u/dcthomp)
#### Post date: [June 10, 2026, 3:30pm UTC](https://discourse.paraview.org/t/how-to-know-whether-a-script-is-executed-by-paraview-python/17610/4 "2026-06-10T15:30:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![CsatiZoltan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/csatizoltan/32/6997_2.png) [@CsatiZoltan](https://discourse.paraview.org/u/CsatiZoltan)
#### Post date: [June 10, 2026, 3:42pm UTC](https://discourse.paraview.org/t/how-to-know-whether-a-script-is-executed-by-paraview-python/17610/5 "2026-06-10T15:42:11Z")

</div>

Running as a command just prints the flag `-c`:

```auto
$ 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:

```auto
$ python3 t.py
t.py
$ pvpython t.py
t.py

```

In interactive mode (REPL), there is nothing:

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

```

---

<div class="post-metadata">

### Author: ![dcthomp](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dcthomp/32/20_2.png) [@dcthomp](https://discourse.paraview.org/u/dcthomp)
#### Post date: [June 10, 2026, 3:42pm UTC](https://discourse.paraview.org/t/how-to-know-whether-a-script-is-executed-by-paraview-python/17610/6 "2026-06-10T15:42:54Z")

</div>

Try `sys.executable`

---

<div class="post-metadata">

### Author: ![CsatiZoltan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/csatizoltan/32/6997_2.png) [@CsatiZoltan](https://discourse.paraview.org/u/CsatiZoltan)
#### Post date: [June 10, 2026, 3:51pm UTC](https://discourse.paraview.org/t/how-to-know-whether-a-script-is-executed-by-paraview-python/17610/7 "2026-06-10T15:51:56Z")

</div>

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