opensim-org / opensim-viewer-backend

Apache License 2.0
1 stars 0 forks source link

Importing `osimViewport` fails due to VTK package issue #10

Open nickbianco opened 3 weeks ago

nickbianco commented 3 weeks ago

I am trying to replicate locally the usage of the OpenSim Viewer in this Jupyter + Google Colab notebook: https://colab.research.google.com/drive/1WdoXOCnygegddK8mDFVeNOC-IdZDqVnO?usp=sharing#scrollTo=AKANMMa6iycq.

Below is a snippet of my installation for the OpenSim Viewer backend. This is installed in a local conda environment along with a custom OpenSim build (which shouldn't affect anything?).

pip install pygltflib
conda install -c conda-forge vtk
git clone https://github.com/opensim-org/opensim-viewer-backend.git

I try to import the Viewer by executing the following:

import sys
sys.path.append('opensim-viewer-backend')
import osimViewport

but I encounter the following error (full stack trace):

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[17], line 1
----> 1 ovp = osimViewport.osimViewport(200, 300)
      2 ovp.addModelAndMotionFiles('squatToStand_3dof9musc.osim', 
      3         ['/squat_to_stand/squat_to_stand_prediction_solution.sto'])
      4 ovp.show()

NameError: name 'osimViewport' is not defined
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[2], line 3
      1 import sys
      2 sys.path.append('opensim-viewer-backend')
----> 3 import osimViewport

File c:\Users\nbianco\repos\CMBBE2024\Demo3_OpenSimMoco\opensim-viewer-backend\osimViewport.py:22
      1 '''
      2     ---------------------------------------------------------------------------
      3     opensim-viewer-backend: osimViewport.py
   (...)
     18     limitations under the License.
     19 '''
     21 from pathlib import Path
---> 22 import osimConverters as osimC
     23 import opensim as osim
     24 import osimConverters.openSimData2Gltf

File c:\Users\nbianco\repos\CMBBE2024\Demo3_[OpenSim](https://opensim.stanford.edu/)Moco\opensim-viewer-backend\osimConverters\__init__.py:5
      3 from .convertC3D2Gltf import *
      4 from .convertMotForce2Gltf import *
----> 5 from .convertOsim2Gltf import *
      6 from .convertOsimZip2Gltf import *
      7 from .osimCamera import *

File c:\Users\nbianco\repos\CMBBE2024\Demo3_OpenSimMoco\opensim-viewer-backend\osimConverters\convertOsim2Gltf.py:10
      7 from pathlib import Path
      9 from .openSimData2Gltf import *
---> 10 from .DecorativeGeometryImplementationGltf import DecorativeGeometryImplementationGltf
     12 def convertOsim2Gltf(osimModelFilePath, geometrySearchPath, motionPaths=[]) :
     14   path = Path(osimModelFilePath)

File c:\Users\nbianco\repos\CMBBE2024\Demo3_OpenSimMoco\opensim-viewer-backend\osimConverters\DecorativeGeometryImplementationGltf.py:4
      2 from pygltflib import *
      3 import numpy as np
----> 4 import vtk
      5 from .openSimData2Gltf import *
      7 # Class to convert osim model file to a GLTF structure.
      8 # The typical workflow would be to instantiate this object, then traverse the model
      9 # adding artifacts to gltf structure cached in this class
     10 # for all geometry objects, wil create a node for the mesh as a child of the frame it lives on
     11 # the node for the frame will correspond to a bodyId, and relative transform

File c:\Users\nbianco\anaconda3\envs\cmbbe2024\Lib\site-packages\vtk.py:30
     28 import importlib
     29 # import vtkmodules.all
---> 30 all_m = importlib.import_module('vtkmodules.all')
     32 # import vtkmodules
     33 vtkmodules_m = importlib.import_module('vtkmodules')

File c:\Users\nbianco\anaconda3\envs\cmbbe2024\Lib\importlib\__init__.py:126, in import_module(name, package)
    124             break
    [1](vscode-notebook-cell:?execution_count=17&line=1)25         level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File c:\Users\nbianco\anaconda3\envs\cmbbe[2](vscode-notebook-cell:?execution_count=17&line=2)024\Lib\site-packages\vtkmodules\all.py:51
     49 from .vtkIOMovie import *
     50 from .vtkIOOggTheora import *
---> 51 from .vtkIONetCDF import *
     52 from .vtkIOMotionFX import *
     5[3](vscode-notebook-cell:?execution_count=17&line=3) from .vtkIOMINC import *

ImportError: DLL load failed while importing vtkIONetCDF: The specified procedure could not be found.

It seems to be an issue with the VTK package installation, as discussed here: https://github.com/conda-forge/vtk-feedstock/issues/207

aymanhab commented 6 days ago

@nickbianco I assume this has been taken care of by the latest moco package, if so I'll mark it done but not close until the official 4.5.1 opensim-moco package is tested