Skip to content

Python plugin with venv not able to import module

Issue

I trying to create a Python plugin that uses a module not installed in pvpython already. I am using a venv to manage the dependencies and then setting the environment variable PV_VENV and using import paraview.web.venv as per this guide. The issue is that when I go to Tools > Manage Plugins... > Load New ... and select my plugin, I receive a ModuleNotFoundError. Before receiving the error, the line ParaView is using venv: <path-to-venv> is printed so I don't understand why the module cannot be found.

Information

I am using ParaView 5.12 in Ubuntu 22.04.4 LTS on Windows Subsystem for Linux.

Steps to Reproduce

  1. Create a test directory: mkdir test and cd test

  2. Create a virtual environment: python -m venv .venv

  3. Activate the virtual environment and install dependencies:

$ source .venv/bin/activate
(.venv) $ pip install numpy intersect
  1. Export PV_VENV environment variable: export PV_VENV="/home/<user>/test/.venv"

  2. Create a test plugin for ParaView:

# plugin.py
import paraview.web.venv
import intersect
  1. Open ParaView and load the plugin:
$ paraview &

then Tools > Manage Plugins... > Load New ... and select plugin.py

  1. Observe the output in the terminal:
(.venv) $ ParaView is using venv: /home/<user>/test/.venv
( 168.986s) [paraview        ]vtkPVPythonAlgorithmPlu:173   WARN| Failed to load Python plugin:
Failed to call `paraview.detail.pythonalgorithm.load_plugin`.
Traceback (most recent call last):
  File "/opt/ParaView-5.12.0-MPI-Linux-Python3.10-x86_64/lib/python3.10/site-packages/paraview/detail/pythonalgorithm.py", line 509, in load_plugin
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/<user>/test/plugin.py", line 3, in <module>
    import intersect
ModuleNotFoundError: No module named 'intersect'

Any ideas what is going on? I tried this a few weeks ago and I was able to load the plugin and import the module from the venv with no issues so I'm not sure what I'm doing differently/what has changed.

Thanks in advance :)

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information