importing dataset_adapter in PV 5.10

I’m having trouble importing dataset_adapter in PV 5.10 using either pvpython or the Python View in the GUI. This is with the installer-based version. I’m not a Python expert but it seems like a bad idea to have a Python module with dashes in it, i.e. What I’m seeing in pvpython is:

>>> from paraview.vtk import dataset_adapter as DA
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'dataset_adapter' from 'paraview.pv-vtk-all' (/home/acbauer/Code/ParaView/ParaView-5.10.0-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/

Am I doing something wrong here or is this a bug? I’m going with the directions from

Using the directions at it imports like:

from vtk.numpy_interface import dataset_adapter as dsa

This seems to be the proper way to do it now.


Dashes are implicitly discouraged in the PEP 8 guidelines, but their presence is not the cause of your issue.

That example is incorrect. I fixed it to use from paraview.vtk.numpy_interface import dataset_adapter as dsa. The example was missing the numpy_interface module. Note that you can also write from vtk.numpy_interface import dataset_adapter as dsa - either works fine.

For more background on importing vtk vs. paraview.vtk, please see this blog post. Basically, if you want anything available in VTK, you can write

import vtk

This imports all of VTK, so it will be slow, hence doing so is discouraged.

If you only need a subset of VTK for commonly used filters, you can write from paraview import vtk. This is faster to import, but may not import all the VTK classes you need.

For ultimate efficiency, you can import only the VTK classes you absolutely need with statements like

from vtkmodules.vtkFiltersCore import vtkSmoothPolyDataFilter

The downside is you need to identify in which module a VTK class exists, but that isn’t too hard.