# Wrap Plugin with python for superbuild

**URL:** https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315
**Category:** ParaView Support
**Tags:** python, vtk
**Created:** [September 14, 2022, 9:13am UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315 "2022-09-14T09:13:31Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![StRuoff](https://discourse.paraview.org/user_avatar/discourse.paraview.org/struoff/32/2060_2.png) [@StRuoff](https://discourse.paraview.org/u/StRuoff)
#### Post date: [September 14, 2022, 9:13am UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/1 "2022-09-14T09:13:31Z")

</div>

Hello ParaView-Community,

I started building my paraview plugin using the [paraview-easy-plugin-builder](https://gitlab.kitware.com/paraview/paraview-easy-plugin-builder). I successfully build my plugin and also tested it in the corresponding paraview release (5.10.0).  
However, I could not get the python wrapping of my plugin to work properly.

Previously, I built my plugin locally on top of a paraview that I built from source, however for the python wrapping, the cmake-files I used do not exist in the superbuild (`vtkPythonWrapping, vtkWrapPython, vtk_wrap_python3, python_add_module`):

```auto
include(vtkPythonWrapping)
include(vtkWrapPython)
vtk_wrap_python3( ThetaReaderPython36 ThetaReaderPython_SRCS "${THETA_READER_WRAP_LIST}" )
# link python library
add_library( ThetaReaderPython36D ${ThetaReaderPython_SRCS} ${THETA_READER_WRAP_LIST} )
python_add_module( ThetaReaderPython36 ThetaReaderInit.cxx )

```

I tried switching to [`vtk_module_wrap_python`](https://vtk.org/doc/nightly/html/group__module-wrapping-python.html#ga0ed7f9062d579088b86e38cc3f66505a), which builds the `.so` file, that I can load succesfully inside pvpython:

```auto
vtk_module_wrap_python(
  MODULES vtkThetaReader
  CMAKE_DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PARAVIEW_PLUGIN_SUBDIR}/${CMAKE_PROJECT_NAME}"
  LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PARAVIEW_PLUGIN_SUBDIR}/${CMAKE_PROJECT_NAME}"
  MODULE_DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PARAVIEW_PLUGIN_SUBDIR}/${CMAKE_PROJECT_NAME}"
  PYTHON_PACKAGE "python"

```

However, the python module is now not available within paraview.simple.

Is there anything I am missing, or did I just put the python-library into the wrong folder (I just keep it in the `Plugin/ThetaReaderModule` folder).  
Maybe I also need to use [`vtk_module_add_python_module`](https://vtk.org/doc/nightly/html/group__module-wrapping-python.html#gad124eb80a5430158912fa6e5a7565af6) or [`vtk_module_add_python_package`](https://vtk.org/doc/nightly/html/group__module-wrapping-python.html#ga2e3cbd2bec4f3c67919e6922b826d55a) for this?

I hope someone can help me or hint into the right direction.

Best  
Stephan

---

<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: [September 14, 2022, 10:00am UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/2 "2022-09-14T10:00:09Z")

</div>

Hi @StRuoff

Thanks for using the plugin builder !

Can you clarify if you are able to make the python wrapping work locally with your own build of ParaView ?

FYI @Francois_Mazen @ben.boeckel

---

<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: [September 14, 2022, 10:02am UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/3 "2022-09-14T10:02:18Z")

</div>

You talk about **ParaView Easy Plugin Builder** but you link the older one, **ParaView Plugin Builder** , can you confirm which project you are using ?

---

<div class="post-metadata">

### Author: ![StRuoff](https://discourse.paraview.org/user_avatar/discourse.paraview.org/struoff/32/2060_2.png) [@StRuoff](https://discourse.paraview.org/u/StRuoff)
#### Post date: [September 14, 2022, 10:16am UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/4 "2022-09-14T10:16:32Z")

</div>

Hello @mwestphal,

I am using the “Easy Builder” and changed the link in the first post accordingly (otherwise Paraview 5.10.0 would not work, right?)

Yes, the wrapping itself works (creates the `vtkThetaReader.so` file), which I can also load in pvpython after setting the PYTHONPATH to the location of the `vtkThetaReader.so` file.  
However, to load my plugin, I have to do:

```python
from vtkThetaReader import vtkThetaReader

```

whereas before I could do:

```python
from paraview.simple import vtkThetaReader

```

---

<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: [September 14, 2022, 10:18am UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/5 "2022-09-14T10:18:18Z")

</div>

In your local build, do you enable specific cmake flags related to python or python wrapping ?

---

<div class="post-metadata">

### Author: ![StRuoff](https://discourse.paraview.org/user_avatar/discourse.paraview.org/struoff/32/2060_2.png) [@StRuoff](https://discourse.paraview.org/u/StRuoff)
#### Post date: [September 14, 2022, 10:31am UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/6 "2022-09-14T10:31:37Z")

</div>

Yes, for my local build (previous setup) I am using the following flags:

```auto
  -DPYTHON_INCLUDE_DIR="${PYTHON_HOME}/include/python3.6m"
  -DPYTHON_LIBRARY="${PYTHON_HOME}/lib/libpython3.6m.so" 

```

and there is this one function I am using (but since it was a while ago I wrote this, don’t know where I got it):

```auto
# PYTHON_ADD_MODULE(<name> src1 src2 ... srcN) is used to build modules for python.
# PYTHON_WRITE_MODULES_HEADER(<filename>) writes a header file you can include
# in your sources to initialize the static python modules
function(PYTHON_ADD_MODULE _NAME )

  # check for shared library property
  get_property(_TARGET_SUPPORTS_SHARED_LIBS
    GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)

  # add options
  option(PYTHON_ENABLE_MODULE_${_NAME} "Add module ${_NAME}" TRUE)
  option(PYTHON_MODULE_${_NAME}_BUILD_SHARED                                    
    "Add module ${_NAME} shared" ${_TARGET_SUPPORTS_SHARED_LIBS})               
                                                                                
  # mark these options as advanced                                              
  mark_as_advanced(
    PYTHON_ENABLE_MODULE_${_NAME}                                
    PYTHON_MODULE_${_NAME}_BUILD_SHARED
  )                                        
                                                                                
  # add python module
  if(PYTHON_ENABLE_MODULE_${_NAME})                                             

    if(PYTHON_MODULE_${_NAME}_BUILD_SHARED)                                     
      set(PY_MODULE_TYPE MODULE)                                                
    else()                                                                      
      set(PY_MODULE_TYPE STATIC)                                                
      set_property(GLOBAL APPEND PROPERTY PY_STATIC_MODULES_LIST ${_NAME})   
    endif()                                                                     
                                                                                
    # add library
    set_property(GLOBAL APPEND PROPERTY PY_MODULES_LIST ${_NAME})            
    add_library(${_NAME} ${PY_MODULE_TYPE} ${ARGN})                             
    # target_link_libraries(${_NAME} ${PYTHON_LIBRARIES})                    
                                                                                
    # set library prefix
    if(PYTHON_MODULE_${_NAME}_BUILD_SHARED)                                     
      set_target_properties(${_NAME} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}")
      if(WIN32 AND NOT CYGWIN)
        set_target_properties(${_NAME} PROPERTIES SUFFIX ".pyd")
      endif()
    endif()
                                                                                
  endif()

endfunction()

```

---

<div class="post-metadata">

### Author: ![StRuoff](https://discourse.paraview.org/user_avatar/discourse.paraview.org/struoff/32/2060_2.png) [@StRuoff](https://discourse.paraview.org/u/StRuoff)
#### Post date: [September 14, 2022, 2:34pm UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/7 "2022-09-14T14:34:31Z")

</div>

Another note I forgot to mention, that may explain the different behavior:

My local install (with custom built paraview) is with paraview Version 5.6.0.

The reason why I wanted to switch to the Easy-Builder was indeed, that I couldn’t get the plugin to work with newer paraview versions.

---

<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: [September 14, 2022, 2:41pm UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/8 "2022-09-14T14:41:39Z")

</div>

Well, you want to make your plugin work with 5.10 locally first.

---

<div class="post-metadata">

### Author: ![StRuoff](https://discourse.paraview.org/user_avatar/discourse.paraview.org/struoff/32/2060_2.png) [@StRuoff](https://discourse.paraview.org/u/StRuoff)
#### Post date: [September 15, 2022, 8:22am UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/9 "2022-09-15T08:22:50Z")

</div>

That’s what I wanted to avoid, since I would have to completely install paraview 5.10.0 from source locally.

Isn’t there any example, on how to wrap a plugin to the vtk/paraview python? Or at least a hint, on where to put the python-library, so that pvpython can find it?

---

<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: [September 15, 2022, 9:03am UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/10 "2022-09-15T09:03:33Z")

</div>

> [@StRuoff](#):
>
> That’s what I wanted to avoid, since I would have to completely install paraview 5.10.0 from source locally.

This is really easy to do the guide is here:  
[https://gitlab.kitware.com/paraview/paraview/-/blob/master/Documentation/dev/build.md#getting-started-guide](https://gitlab.kitware.com/paraview/paraview/-/blob/master/Documentation/dev/build.md#getting-started-guide)

> Isn’t there any example, on how to wrap a plugin to the vtk/paraview python? Or at least a hint, on where to put the python-library, so that pvpython can find it?

The wrapping si automatic and should not require anything specific in your plugin. You should be able to load your plugin and just use the python shell as if the code you built is part of actual paraview.

---

<div class="post-metadata">

### Author: ![StRuoff](https://discourse.paraview.org/user_avatar/discourse.paraview.org/struoff/32/2060_2.png) [@StRuoff](https://discourse.paraview.org/u/StRuoff)
#### Post date: [September 15, 2022, 1:22pm UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/11 "2022-09-15T13:22:08Z")

</div>

Ok, So I think I found the solution (or rather my error):

When I finished building the Plugin, I copied it to `$PARAVIEW_DIR/plugins` instead of `$PARAVIEW_DIR/lib/paraview-5.10./plugins`.  
Now the plugin is automatically found by paraview and can be imported via  
`from paraview.simple import vtkThetaReader`

---

<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: [September 15, 2022, 1:25pm UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/12 "2022-09-15T13:25:41Z")

</div>

Ok, but I want to mention that you are not supposed to put your own plugins there, there is dedicated mechanism for that.

---

<div class="post-metadata">

### Author: ![StRuoff](https://discourse.paraview.org/user_avatar/discourse.paraview.org/struoff/32/2060_2.png) [@StRuoff](https://discourse.paraview.org/u/StRuoff)
#### Post date: [September 15, 2022, 1:40pm UTC](https://discourse.paraview.org/t/wrap-plugin-with-python-for-superbuild/10315/13 "2022-09-15T13:40:37Z")

</div>

I see…

I reread all the info on the Plugins from the [HowTo](https://www.paraview.org/Wiki/ParaView/Plugin_HowTo#Using_Plugins) and found another mistake I (unintenionally) made:  
I forgot to set the `PV_PLUGIN_PATH` variable.  
When I set it to point to the `$PARAVIEW_DIR/plugins` folder, everything loads fine and also the python-import still works as expected.
