Sunday, April 25, 2010

PythonXY 2.6.2 + Panda3d 1.7.0 + JModelica 1.1b1 – How to get to work together

If Panda3D 1.7.0 is added to Python using a ‘pth’ file, then JModelica 1.1b1 will load the wrong ‘mscvrt.dll’ and fail to initialize. This problem occurs:

In [1]: import jmodelica.examples.cstr as cstr
C:\Python26\lib\site-packages\jpype\ DeprecationWarning: the s
ets module is deprecated
  import sets
OSError                                   Traceback (most recent call last)

C:\\work\<ipython console> in <module>()

C:\\Python\jmodelica\examples\ in <module>()
      9 from jmodelica.initialization.ipopt import NLPInitialization
     10 from jmodelica.initialization.ipopt import InitializationOptimizer
---> 11 from jmodelica.simulation.sundials import TrajectoryLinearInterpolation
     12 from jmodelica.simulation.sundials import SundialsDAESimulator
     13 from jmodelica.optimization import ipopt

C:\\Python\jmodelica\simulation\ in <module>()
     15 try:
---> 16     from pysundials import cvodes
     17     from pysundials import ida
     18     from pysundials import nvecserial

C:\Python26\lib\site-packages\pysundials\ in <module>()
     39 import ctypes
---> 40 import sundials_core
     41 import nvecserial

C:\Python26\lib\site-packages\pysundials\ in <module>()
     87 f.close()
---> 89 libc = loadlib("c")
     90 try:
     91         libc.fdopen.argtypes = [ctypes.c_int, ctypes.c_int]

C:\Python26\lib\site-packages\pysundials\ in loadlib(libname)
     63                 lib = ctypes.CDLL(libpaths[libname])
     64         except OSError, e:
---> 65                 raise OSError("%s\nCannot load shared library %s. Please
check you config file and ensure the paths to the shared libraries are correct.
"%(e, libpaths[libname]))
     66         return lib

OSError: [Error 1114] A dynamic link library (DLL) initialization routine failed

Cannot load shared library C:\Panda3D-1.7.0\bin\msvcrt.dll. Please check you con
fig file and ensure the paths to the shared libraries are correct.

The occurs in pysundials because the util.find_library('msvcrt') in the ctypes module is attempting to load the ‘msvcrt.dll’ which is installed with Panda3D. This problem can be fixed by forcing pysundials to load a compatible msvcrt.dll file, rather than the most recent. This is done by modifying to point to the correct dll. The following change starting at line 42 will force a specific dll to be loaded. The path and dll to use will be specific to each system.

if == "nt":
    #clib = util.find_library('msvcrt')
    clib = 'C:\\Program Files (x86)\\Java\\jdk1.6.0_17\\jre\\bin\\msvcrt.dll'
    clib = util.find_library('c')

1 comment:

  1. does not longer rely on pysundias, but rather the simulation package Assimulo ( Possibly, this also solves the problem.