Experiencing ImportErrror when loading vtk constants

Hi VTK forum,

I am getting an error when importing vtk (as part of brainspace)

ImportError: cannot import name 'VTK_UNICODE_STRING' from 'vtk.util.vtkConstants'

from the following command:

from brainspace.null_models import MoranRandomization

I am using python 3.8.10, based on this post VTK import error when trying to import PyVista on Python 3.10 - Stack Overflow I have tried to install older versions of vtk.

Could anyone suggest other solutions?

Full error message:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_1725920/2766125407.py in <module>
----> 1 from brainspace.null_models import MoranRandomization

~/.local/lib/python3.8/site-packages/brainspace/null_models/__init__.py in <module>
----> 1 from .moran import (compute_mem, moran_randomization,
      2                     MoranRandomization)
      3 from .spin import spin_permutations, SpinPermutations
      4 
      5 

~/.local/lib/python3.8/site-packages/brainspace/null_models/moran.py in <module>
     14 from sklearn.base import BaseEstimator
     15 
---> 16 from ..mesh import mesh_elements as me
     17 from ..gradient.utils import is_symmetric, make_symmetric
     18 

~/.local/lib/python3.8/site-packages/brainspace/mesh/__init__.py in <module>
----> 1 from . import (array_operations, mesh_elements, mesh_correspondence,
      2                mesh_cluster, mesh_creation, mesh_operations, mesh_io)
      3 
      4 __all__ = ['array_operations',
      5            'mesh_elements',

~/.local/lib/python3.8/site-packages/brainspace/mesh/array_operations.py in <module>
     20                  mutable as vtk_mutable)
     21 
---> 22 from . import mesh_elements as me
     23 from .mesh_operations import mask_points
     24 from ..utils.parcellation import map_to_mask, reduce_by_labels

~/.local/lib/python3.8/site-packages/brainspace/mesh/mesh_elements.py in <module>
     14 import vtk
     15 
---> 16 from ..vtk_interface import wrap_vtk, serial_connect
     17 from ..vtk_interface.decorators import wrap_input
     18 

~/.local/lib/python3.8/site-packages/brainspace/vtk_interface/__init__.py in <module>
----> 1 from .wrappers.base import (wrap_vtk, unwrap_vtk, wrap_vtk_array,
      2                             unwrap_vtk_array, is_vtk, is_wrapper)
      3 from .pipeline import serial_connect, to_data, get_output
      4 
      5 

~/.local/lib/python3.8/site-packages/brainspace/vtk_interface/wrappers/__init__.py in <module>
----> 1 from .base import BSVTKObjectWrapper
      2 from .data_object import BSTable, BSPolyData, BSUnstructuredGrid
      3 from .algorithm import (BSDataSetMapper, BSPolyDataMapper,
      4                         BSLabeledContourMapper, BSLabeledDataMapper,
      5                         BSLabelPlacementMapper, BSPolyDataMapper2D,

~/.local/lib/python3.8/site-packages/brainspace/vtk_interface/wrappers/base.py in <module>
     13 from vtk.util.vtkConstants import VTK_STRING
     14 
---> 15 from .utils import call_vtk, get_vtk_methods, is_numpy_string, is_vtk_string
     16 
     17 

~/.local/lib/python3.8/site-packages/brainspace/vtk_interface/wrappers/utils.py in <module>
     13 import numpy as np
     14 
---> 15 from vtk.util.vtkConstants import VTK_BIT, VTK_STRING, VTK_UNICODE_STRING
     16 
     17 

ImportError: cannot import name 'VTK_UNICODE_STRING' from 'vtk.util.vtkConstants' (/home/max/.local/lib/python3.8/site-packages/vtkmodules/util/vtkConstants.py)

VTK_UNICODE_STIRNG has been removed as of 9.2.0; just use VTK_STRING instead.

1 Like