# How embedding Python Source as Modules?

**URL:** https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978
**Category:** ParaView Support
**Created:** [June 3, 2019, 8:48am UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978 "2019-06-03T08:48:06Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![e-kolosov](https://discourse.paraview.org/user_avatar/discourse.paraview.org/e-kolosov/32/2375_2.png) [@e-kolosov](https://discourse.paraview.org/u/e-kolosov)
#### Post date: [June 3, 2019, 8:48am UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/1 "2019-06-03T08:48:06Z")

</div>

Hello.  
I read the instruction [https://www.paraview.org/Wiki/ParaView/Plugin\_HowTo](https://www.paraview.org/Wiki/ParaView/Plugin_HowTo) and build a simple HelloWorldRedaer but it doesn’t work. It load a dynamic library but can’t apply a HelloWorldReader reader.

 ![hello_world_reader](https://discourse.paraview.org/uploads/default/original/2X/a/aafa0e67ae242b82c70611a2a59af4be95365b71.png)  
 ![hello_world_reader_python_shell](https://discourse.paraview.org/uploads/default/original/2X/f/fec1809bd66d88803ef48fb75bc9cedfc273bdfd.png)  
What I doing wrong? Please, review my example.  
[HelloWorldReader.tar.gz](https://discourse.paraview.org/uploads/default/original/2X/4/48e984a36332a0387a3a684bba22aa9804e52b42.gz) (882 Bytes)

Thanks in advance.

---

<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: [June 3, 2019, 9:41am UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/2 "2019-06-03T09:41:09Z")

</div>

do not import it, just use it.

`HelloWorldReader()`

---

<div class="post-metadata">

### Author: ![e-kolosov](https://discourse.paraview.org/user_avatar/discourse.paraview.org/e-kolosov/32/2375_2.png) [@e-kolosov](https://discourse.paraview.org/u/e-kolosov)
#### Post date: [June 3, 2019, 9:44am UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/3 "2019-06-03T09:44:13Z")

</div>

it does not work too

 ![hello_world_reader_python_shell2](https://discourse.paraview.org/uploads/default/original/2X/7/71ece8dee056d4d467a413a08d108d2ab954aedd.png)

---

<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: [June 3, 2019, 9:47am UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/4 "2019-06-03T09:47:24Z")

</div>

I missed the fact that you are using a python module (as described in the Howto)

It is more simpler now, take a look into the paraview sources:  
`./Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py`

---

<div class="post-metadata">

### Author: ![e-kolosov](https://discourse.paraview.org/user_avatar/discourse.paraview.org/e-kolosov/32/2375_2.png) [@e-kolosov](https://discourse.paraview.org/u/e-kolosov)
#### Post date: [June 3, 2019, 10:01am UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/5 "2019-06-03T10:01:30Z")

</div>

Thanks, Mathieu.  
Maybe I don’t understand but it is examples of clear python filters. And it’s working. But I can’t embedding python source as module (native dynamic library). Is it possible? What should I doing for that?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [June 3, 2019, 1:53pm UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/6 "2019-06-03T13:53:35Z")

</div>

This wasn’t updated in the new module system because ParaView didn’t have any up-to-date plugins doing Python (`.py`) module loading. Do you have a plugin I could use to implement the functionality?

---

<div class="post-metadata">

### Author: ![e-kolosov](https://discourse.paraview.org/user_avatar/discourse.paraview.org/e-kolosov/32/2375_2.png) [@e-kolosov](https://discourse.paraview.org/u/e-kolosov)
#### Post date: [June 3, 2019, 2:20pm UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/7 "2019-06-03T14:20:13Z")

</div>

Ben, thanks for the reply. I have about 15 python plugins and I need embedding them. If you can update the example that I uploaded in the first message then I can rewrite my scripts for embedding.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [June 3, 2019, 7:06pm UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/8 "2019-06-03T19:06:02Z")

</div>

OK, I’ll try and take a look at it. Thanks for the example. Mind if I add the `HelloWorldReader` to ParaView as an example when it’s ported?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [June 3, 2019, 10:56pm UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/9 "2019-06-03T22:56:59Z")

</div>

This fixes ParaView’s module loading so that it can work: [https://gitlab.kitware.com/paraview/paraview/merge\_requests/3308](https://gitlab.kitware.com/paraview/paraview/merge_requests/3308). For your plugin, changing it to be an actual package (I did `HelloWorldReader/{ __init__.py,hello_world_reader.py}`), it now loads properly. However, I don’t know how to actually use the plugin to get the proxy to show up in the File \> Open dialog. @mwestphal @utkarsh.ayachit Any ideas?

---

<div class="post-metadata">

### Author: ![e-kolosov](https://discourse.paraview.org/user_avatar/discourse.paraview.org/e-kolosov/32/2375_2.png) [@e-kolosov](https://discourse.paraview.org/u/e-kolosov)
#### Post date: [June 4, 2019, 6:58am UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/10 "2019-06-04T06:58:49Z")

</div>

Thank you, Ben.

> Mind if I add the `HelloWorldReader` to ParaView as an example when it’s ported?

Yes of course you can add this example.

> However, I don’t know how to actually use the plugin to get the proxy to show up in the File \> Open dialog.

If I understand correctly, now it also does not work?

---

<div class="post-metadata">

### Author: ![e-kolosov](https://discourse.paraview.org/user_avatar/discourse.paraview.org/e-kolosov/32/2375_2.png) [@e-kolosov](https://discourse.paraview.org/u/e-kolosov)
#### Post date: [June 4, 2019, 7:42am UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/12 "2019-06-04T07:42:14Z")

</div>

Offtopic: Can I autoload python based filters without using GUI (.pyc format is preferred) as a temporary solution?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [June 4, 2019, 1:16pm UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/13 "2019-06-04T13:16:57Z")

</div>

Hmm, I don’t think so. @utkarsh.ayachit Is there a way to do that?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [June 4, 2019, 1:17pm UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/14 "2019-06-04T13:17:25Z")

</div>

> [@e-kolosov](#):
>
> If I understand correctly, now it also does not work?

This is more likely me not knowing how to use the plugin 🙂 .

---

<div class="post-metadata">

### Author: ![e-kolosov](https://discourse.paraview.org/user_avatar/discourse.paraview.org/e-kolosov/32/2375_2.png) [@e-kolosov](https://discourse.paraview.org/u/e-kolosov)
#### Post date: [June 4, 2019, 1:57pm UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/15 "2019-06-04T13:57:08Z")

</div>

> Offtopic: Can I autoload python based filters without using GUI (.pyc format is preferred) as a temporary solution?

I fixed vtkPVPluginLoader and now it’s possible to autoload python (.py format) filters without GUI. I can share it if need.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [June 4, 2019, 2:55pm UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/16 "2019-06-04T14:55:42Z")

</div>

> [@e-kolosov](#):
>
> I fixed vtkPVPluginLoader and now it’s possible to autoload python (.py format) filters without GUI. I can share it if need.

That’d be great!

So after talking here, it seems that here’s the current status:

- The `PYTHON_MODULES` argument to `paraview_add_plugin` is working as-intended as of the above MR. This makes code available to `import` in the shell after loading the associated plugin
- Proxy Python filters should be loaded directly through the load plugin dialog. This makes them available for use in the `paraview.simple` module.
- What your example is doing is making a proxy in a module made available in a plugin. This is the intersection of the above two use cases and is not currently supported.

There are some obstacles to overcome before this can happen:

- Separate client/server cases would need to make the proxy available on the server as well by loading the plugin and then importing the associated proxy.
- Proxies are registered globally right now by inspecting the globals of the module after direct importing. The decorators would need to learn how to register upon being called instead.

I’ve filed an issue for this here: [https://gitlab.kitware.com/paraview/paraview/issues/19063](https://gitlab.kitware.com/paraview/paraview/issues/19063)

---

<div class="post-metadata">

### Author: ![e-kolosov](https://discourse.paraview.org/user_avatar/discourse.paraview.org/e-kolosov/32/2375_2.png) [@e-kolosov](https://discourse.paraview.org/u/e-kolosov)
#### Post date: [June 5, 2019, 10:08am UTC](https://discourse.paraview.org/t/how-embedding-python-source-as-modules/1978/17 "2019-06-05T10:08:56Z")

</div>

> [@ben.boeckel](#):
>
> That’d be great!

I’ve filed an issue for this here: [https://gitlab.kitware.com/paraview/paraview/issues/19065](https://gitlab.kitware.com/paraview/paraview/issues/19065)  
and created a merge request with the implementation of this issue [https://gitlab.kitware.com/paraview/paraview/merge\_requests/3310](https://gitlab.kitware.com/paraview/paraview/merge_requests/3310)
