K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
941 stars 123 forks source link

Module import issue while running `volume_renderer.ipynb` example #406

Closed DeepaMahm closed 1 year ago

DeepaMahm commented 1 year ago

Hi All,

I am a beginner here. I am trying to run the following example in jupyter notebook.

import k3d
import math
import numpy as np
import nibabel as nib
from k3d.helpers import download
import ipywidgets as widgets
import vtk
from vtkmodules.util import numpy_support
basic_color_maps = [(attr, getattr(k3d.basic_color_maps, attr)) for attr in dir(k3d.basic_color_maps) if
                    not attr.startswith('__')]
paraview_color_maps = [(attr, getattr(k3d.paraview_color_maps, attr)) for attr in dir(k3d.paraview_color_maps) if
                       not attr.startswith('__')]
matplotlib_color_maps = [(attr, getattr(k3d.matplotlib_color_maps, attr)) for attr in dir(k3d.matplotlib_color_maps)
                         if not attr.startswith('__')]
colormaps = basic_color_maps + paraview_color_maps + matplotlib_color_maps

filename = download('https://vedo.embl.es/examples/data/embryo.slc')
reader = vtk.vtkSLCReader()
reader.SetFileName(filename)
reader.Update()
vti = reader.GetOutput()

bounds = vti.GetBounds()
x, y, z = vti.GetDimensions()
img = numpy_support.vtk_to_numpy(vti.GetPointData().GetArray(0)).reshape(-1, y, x)

tf_editor = k3d.transfer_function_editor()
volume = k3d.volume(img.astype(np.float16))

@widgets.interact(x=widgets.Dropdown(options=colormaps, description='ColorMap:'))
def g(x):
    tf_editor.color_map = np.array(x, dtype=np.float32)

plot = k3d.plot()
plot += volume
tf_editor.display()
plot.display()

a = widgets.jslink((tf_editor, 'color_map'), (volume, 'color_map'))
a = widgets.jslink((tf_editor, 'opacity_function'), (volume, 'opacity_function'))

and I get the following error


ImportError                               Traceback (most recent call last)
~\anaconda3\lib\site-packages\vtkmodules\vtkIOImage.py in <module>
      4     # use relative import for installed modules
----> 5     from .vtkIOImagePython import *
      6 except ImportError:

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-5-b5758b6de607> in <module>
      5 from k3d.helpers import download
      6 import ipywidgets as widgets
----> 7 import vtk
      8 from vtkmodules.util import numpy_support
      9 basic_color_maps = [(attr, getattr(k3d.basic_color_maps, attr)) for attr in dir(k3d.basic_color_maps) if

~\anaconda3\lib\site-packages\vtk.py in <module>
     30     all_spec = importlib.util.find_spec('vtkmodules.all')
     31     all_m = importlib.util.module_from_spec(all_spec)
---> 32     all_spec.loader.exec_module(all_m)
     33 
     34     # import vtkmodules

~\anaconda3\lib\site-packages\vtkmodules\all.py in <module>
     54 from .vtkFiltersTopology import *
     55 from .vtkFiltersVerdict import *
---> 56 from .vtkIOImage import *
     57 from .vtkImagingHybrid import *
     58 from .vtkInfovisLayout import *

~\anaconda3\lib\site-packages\vtkmodules\vtkIOImage.py in <module>
      7     # during build and testing, the modules will be elsewhere,
      8     # e.g. in lib directory or Release/Debug config directories
----> 9     from vtkIOImagePython import *

ModuleNotFoundError: No module named 'vtkIOImagePython'

I checked the files available in vtkmodules folder in the anaconda environment

image

and I could only find the vtkIOImagePython.pyd file and not vtkIOImagePython.py.

I'm using Windows.

I am not sure how to solve this error. Suggestions will be really helpful. Thanks a lot for your time and kind attention.