# Open Paraview GUI with python functions laoded

**URL:** https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779
**Category:** ParaView Support
**Created:** [January 14, 2022, 1:29pm UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779 "2022-01-14T13:29:25Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![whiteW](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@whiteW](https://discourse.paraview.org/u/whiteW)
#### Post date: [January 14, 2022, 1:29pm UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779/1 "2022-01-14T13:29:26Z")

</div>

Dear all,

I would like to start the GUI of Paraview with some python functions loaded in memory.

Now I’m using the following command to open Paraview and execute a script (that also contains some python functions)

> paraview --script=pws\_auto.py

In this case I can automatically execute all the commands in the script (that uses its python functions) when the GUI opens, however once the script is executed, if I click the pythonShell of Paraview, it seems like the environment is initialized and that the python functions of the script don’t exists: they are not loaded.

On the other hand If I manually open Paraview and load the script using the “Run script” button , then I can use the functions in the script.

I would like to open the GUI with the previous bash command and once the script terminates I would line to use the function inside it from the phytonShell, without having to re-load the script with the button.

Is it possible?

Thanks

WhiteW

---

<div class="post-metadata">

### Author: ![whiteW](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@whiteW](https://discourse.paraview.org/u/whiteW)
#### Post date: [January 16, 2022, 5:43pm UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779/2 "2022-01-16T17:43:29Z")

</div>

This problem seems to be similar to the one described here:

> [@Python shell reset on first use with Paraview 5.6](https://discourse.paraview.org/t/python-shell-reset-on-first-use-with-paraview-5-6/2978):
>
> Hello, I’ve got an issue with Paraview 5.6.0 with the use of script. I open the GUI of ParaView with command line and the use of --script=name\_of\_script.py to execute a python script at the openning This open me the GUI of Paraview and execute some operations like loading geometry and perform some post processing. And also load some home made python libraries with post-processing functions like plot line at location of interest if wanted by the user. With ParaView 5.4, after the sc…

Why the Python Shell resets at startup even if a script has run?

Is there a workaround? A way to suggest paraview to load some python functions at atartup?  
A sort of:

`from startupscript.py import *`

to be always executed when paraview is opened?

Thanks,  
WhiteW

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 17, 2022, 9:22am UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779/3 "2022-01-17T09:22:53Z")

</div>

This is a limitation of ParaView, it could be fixed imo.

A work around is to load your script using a xml test actually using the python shell to load it.

---

<div class="post-metadata">

### Author: ![whiteW](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@whiteW](https://discourse.paraview.org/u/whiteW)
#### Post date: [January 17, 2022, 9:51am UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779/4 "2022-01-17T09:51:19Z")

</div>

Hello Matheiu,

Thanks for your reply.  
If I open the Paraview GUI I’m already able to load my python script and functions from the Python Shell (using the run script button).  
So using this xml test is possible to open the Paraview GUI with already the functions loaded?  
Can you provide a small example or suggest me how to create this xml file?

Thanks!  
WhiteW

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 17, 2022, 9:57am UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779/5 "2022-01-17T09:57:38Z")

</div>

`./bin/paraview --dr --test-script=/home/glow/tmp/scripts.xml`

[scripts.xml](https://discourse.paraview.org/uploads/short-url/asf1W2hGnhZE7NH0hTyOSPex2xD.xml) (428 Bytes)

in scripts.xml, point to your own python script

---

<div class="post-metadata">

### Author: ![whiteW](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@whiteW](https://discourse.paraview.org/u/whiteW)
#### Post date: [January 17, 2022, 10:20am UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779/6 "2022-01-17T10:20:35Z")

</div>

Thanks, it works!  
Now I can find my functions loaded in the python shell.

There is another little problem. Now the Paraview GUI opens however the Python shell does not appear at startup as before. I must activate it from View/python Shell (and the functions are correctly loaded inside it).  
How can I force Paraview to start with already the shell active as before?

Thanks,  
WhiteW

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 17, 2022, 10:23am UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779/7 "2022-01-17T10:23:07Z")

</div>

because your are using `--dr`.

---

<div class="post-metadata">

### Author: ![whiteW](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@whiteW](https://discourse.paraview.org/u/whiteW)
#### Post date: [January 17, 2022, 10:25am UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779/8 "2022-01-17T10:25:17Z")

</div>

Hi,  
I tried also without the -dr option and the functions are correctly loaded but the python shell is closed at startup.  
WhiteW

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 17, 2022, 10:27am UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779/9 "2022-01-17T10:27:03Z")

</div>

Because your close it in the script, here is a modified version that do not close it:

[scripts.xml](https://discourse.paraview.org/uploads/short-url/6k4lRfDUWZtVqH3RZpNRxwsv6BD.xml) (324 Bytes)

---

<div class="post-metadata">

### Author: ![whiteW](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@whiteW](https://discourse.paraview.org/u/whiteW)
#### Post date: [January 17, 2022, 2:16pm UTC](https://discourse.paraview.org/t/open-paraview-gui-with-python-functions-laoded/8779/10 "2022-01-17T14:16:24Z")

</div>

Hi Mathieu,  
This is what I needed. Now everythig woks properly.  
Thanks a lot for your help!  
WhiteW
