# Python plugin split into multiple modules

**URL:** https://discourse.paraview.org/t/python-plugin-split-into-multiple-modules/16100
**Category:** Development
**Tags:** python
**Created:** [February 3, 2025, 12:58pm UTC](https://discourse.paraview.org/t/python-plugin-split-into-multiple-modules/16100 "2025-02-03T12:58:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![marek.paty](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/m/9fc348/32.png) [@marek.paty](https://discourse.paraview.org/u/marek.paty)
#### Post date: [February 3, 2025, 12:58pm UTC](https://discourse.paraview.org/t/python-plugin-split-into-multiple-modules/16100/1 "2025-02-03T12:58:11Z")

</div>

I am using ParaView 5.13 on linux and I would like to create a Python plugin which consists of multiple modules. The purpose is to make the structure better organized and to be able to reuse the different modules in other plugins in future. I have a main script called `SwirlingStreamlines.py` and I would like to import a module called `SeedPoints.py`. I am using the command `import SeedPoints` in `SwirlingStreamlines.py`. When I try to load the plugin into ParaView, I am getting the following error:

```auto
Traceback (most recent call last):
  File "/home/marek/paraview_build/lib/python3.10/site-packages/paraview/detail/pythonalgorithm.py", line 538, in load_plugin
    module = imp.load_source(modulename, filepath)
  File "/home/marek/anaconda3/lib/python3.10/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 719, in _load
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/marek/Workspace/ParaviewPlugins/Python/VortexIdentification/SwirlingStreamlines.py", line 13, in <module>
    import SeedPoints
ModuleNotFoundError: No module named 'SeedPoints'
( 1.187s) [paraview] vtkPVPluginLoader.cxx:670 ERR| vtkPVPluginLoader (0x55aedfb2bb60): /home/marek/Workspace/ParaviewPlugins/Python/VortexIdentification/SwirlingStreamlines.py: /home/marek/Workspace/ParaviewPlugins/Python/VortexIdentification/SwirlingStreamlines.py: invalid ELF header

```

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [February 3, 2025, 2:00pm UTC](https://discourse.paraview.org/t/python-plugin-split-into-multiple-modules/16100/2 "2025-02-03T14:00:56Z")

</div>

I think there are some `path` issues to solve: the directory containing your main `.py` is not added to the `PYTHONPATH` so “relative” imports are not possible.

A workaround I see is something like the following:

Main directory:

```auto
SwirlingStreamlines.py
MyModule
 |_ SeedPoints.py

```

SwirlingStreamLines.py

```auto
import os,sys
sys.path.append(os.path.dirname( __file__ ))

from MyModule import SeedPoints

```

---

<div class="post-metadata">

### Author: ![marek.paty](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/m/9fc348/32.png) [@marek.paty](https://discourse.paraview.org/u/marek.paty)
#### Post date: [February 4, 2025, 9:02am UTC](https://discourse.paraview.org/t/python-plugin-split-into-multiple-modules/16100/3 "2025-02-04T09:02:49Z")

</div>

Thank you Nicolas, the proposed solution works!
