Showing posts with label JModelica. Show all posts
Showing posts with label JModelica. Show all posts

Friday, April 8, 2011

Installing JModelica after PythonXY

To get JModelica 1.5 to work with PythonXY 2.6.5.6 on win7 Professional, the following steps will work:
  1. Install PythonXY using default options.
  2. Start the JModelica install. When given a choice on where install, choose C:\.
  3. Add a path file to the site-packages directory in python. In a default install of PythonXY, the location is “C:\Python26\Lib\site-packages”. The name of the file should be “jmodelica.pth”. The contents of the file is a single line “C:\JModelica.org-1.5\Python”. To understand how Python paths work, see this reference.
  4. Open “C:\JModelica.org-1.5\setenv.bat” with a text editor. Manually set all of the environment variables in your system to match the environment variables defined in this file.
  5. Start a python interpreter in PythonXY.
  6. Follow the direction for testing in “C:\JModelica.org-1.5\README.TXT”. The tests should complete successfully.
Addendum:
   This approach also works with JModelica 1.6 and PythonXY 2.7.2.
   Simply substitute "JModelica.org-1.6" for "JModelica.org-1.5" in the above steps.
This work is licensed under a Creative Commons Attribution By license.

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\_pykeywords.py:18: DeprecationWarning: the s
ets module is deprecated
  import sets
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)

C:\JModelica.org-1.1b1\work\<ipython console> in <module>()

C:\JModelica.org-1.1b1\Python\jmodelica\examples\cstr.py 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:\JModelica.org-1.1b1\Python\jmodelica\simulation\sundials.py in <module>()
     14
     15 try:
---> 16     from pysundials import cvodes
     17     from pysundials import ida
     18     from pysundials import nvecserial

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

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

C:\Python26\lib\site-packages\pysundials\sundials_core.py 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
     67

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 pysundials_core.py 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 os.name == "nt":
    #clib = util.find_library('msvcrt')
    clib = 'C:\\Program Files (x86)\\Java\\jdk1.6.0_17\\jre\\bin\\msvcrt.dll'
else:
    clib = util.find_library('c')