I wrote a Python plugin, which imports other custom Python modules (helper modules that I wrote myself). After setting PYTHONPATH and then launching ParaView, I can load the plugin successfully and it works as intended.
Now I want to compile the Python plugin. The compilation is successful, but I get an import error when loading the .so file in the Plugin Manager. In my project setup, I mimicked the PythonAlgorithm example. I added a line in PythonAlgorithmExamples.py:
import other_module
where the content of other_module.py is simply
# other_module.py
print('Imported "other_module"')
I changed a line in CMakeLists.txt:
PYTHON_MODULES PythonAlgorithmExamples.py other_module.py
The compilation is successful, but when I load the plugin in ParaView 6.1.1, I get
Generic Warning: In vtkPVPythonAlgorithmPlugin.cxx, line 235
Failed to load Python plugin:
Failed to call `paraview.detail.pythonalgorithm.load_plugin_from_string`
Traceback (most recent call last):
File "/home/zc/Programs/ParaView-6.1.1-MPI-Linux-Python3.12-x86_64/lib/python3.12/site-packages/paraview/detail/pythonalgorithm.py", line 546, in load_plugin_from_string
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<not a real path>/PythonAlgorithmExamples.py", line 5, in <module>
ModuleNotFoundError: No module named 'other_module'
Imported "other_module"
Imported "other_module"
It is interesting that although I get these import errors, the module is still imported somehow (although the original functionalities of the example plugin do not work).
When trying without modifications of the PYTHON_MODULES line, i.e.
PYTHON_MODULES PythonAlgorithmExamples.py
I get the same error message, but the code in other_module.py is not executed anymore.
Generic Warning: In vtkPVPythonAlgorithmPlugin.cxx, line 235
Failed to load Python plugin:
Failed to call `paraview.detail.pythonalgorithm.load_plugin_from_string`
Traceback (most recent call last):
File "/home/zc/Programs/ParaView-6.1.1-MPI-Linux-Python3.12-x86_64/lib/python3.12/site-packages/paraview/detail/pythonalgorithm.py", line 546, in load_plugin_from_string
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<not a real path>/PythonAlgorithmExamples.py", line 5, in <module>
ModuleNotFoundError: No module named 'other_module'
Generic Warning: In vtkPVPythonAlgorithmPlugin.cxx, line 235
Failed to load Python plugin:
Failed to call `paraview.detail.pythonalgorithm.load_plugin_from_string`
Traceback (most recent call last):
File "/home/zc/Programs/ParaView-6.1.1-MPI-Linux-Python3.12-x86_64/lib/python3.12/site-packages/paraview/detail/pythonalgorithm.py", line 546, in load_plugin_from_string
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<not a real path>/PythonAlgorithmExamples.py", line 5, in <module>
ModuleNotFoundError: No module named 'other_module'
Looking at other examples, I found the pvblot plugin, which uses multiple modules. But that plugin is deactivated, so I cannot build it to try it out.
Do you have an idea why the import does not work when compiled?