Python wrapper OpenSim 3.2

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Marco Capogrosso
Posts: 7
Joined: Thu Jul 19, 2012 4:24 pm

Python wrapper OpenSim 3.2

Post by Marco Capogrosso » Tue Jun 17, 2014 2:20 am

Hi,
Hoping you could help me I'm posting the problem I have when compiling OpenSim 3.2 on Mac,
Everything works fine, building Simbody 3.3.1 and OpenSim itself, the only problem is that when I try to compile it with Python Wrapper, and I use the python routine setup.py, It generates everything BUT
the library which is generated is "_opensim.dylib".
Now, apparently, for some odd bug in python, when you try to type "import opensim" in python, it lopensim.py is not able to load the "_opensim" module like he can't find the library.
In particular the problem is in the line:

Code: Select all

fp, pathname, description = imp.find_module('_opensim', [dirname(__file__)])
so a call like "import opensim" would give this error:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "opensim.py", line 26, in <module>
    _opensim = swig_import_helper()
  File "opensim.py", line 18, in swig_import_helper
    import _opensim
ImportError: No module named _opensim
This is because of this bug, which could potentially be solved by compiling in .so instead that .dylib, so I tried to change the extension of the file to _opensim.so. In this way "opensim.py" is able to find the module but what you get now is this:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/opensim-3.2-py2.7.egg/opensim/__init__.py", line 1, in <module>
    from opensim import *
  File "/Library/Python/2.7/site-packages/opensim-3.2-py2.7.egg/opensim/opensim.py", line 26, in <module>
    _opensim = swig_import_helper()
  File "/Library/Python/2.7/site-packages/opensim-3.2-py2.7.egg/opensim/opensim.py", line 22, in swig_import_helper
    _mod = imp.load_module('_opensim', fp, pathname, description)
ImportError: dynamic module does not define init function (init_opensim)
He is able to find the library but somehow not to point to the correct functions.
Is there a way around this? I thought if it could be possible to compile directly as .so instead of .dyliv but I don't know where to look for.
As it is now, It looks like for mac the python module does not work, and now I'm really out of options.

I would appreciate any help,
thanks

Marco

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Python wrapper OpenSim 3.2

Post by Christopher Dembia » Thu Jun 19, 2014 12:29 am

See my second post at https://simtk.org/forums/viewtopic.php? ... 179#p12179 for your init_opensim problem.

As for the .dylib issue, try editing OpenSim/Wrapping/Python/CMakeLists.txt at line 63 using the following:

IF(WIN32)
SET_TARGET_PROPERTIES(_${KIT} PROPERTIES SUFFIX ".pyd")
ELSEIF(APPLE)
SET_TARGET_PROPERTIES(_${KIT} PROPERTIES SUFFIX ".so")
ENDIF()

Let me know if this works.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Python wrapper OpenSim 3.2

Post by Christopher Dembia » Mon Jul 07, 2014 2:05 pm

See the new source release of OpenSim 3.2: https://simtk.org/frs/download.php?file_id=4085 It contains fixes for the issues you ran into.

POST REPLY