Using OpenSim Python on M1 Mac Silicon

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Victor Ng-Thow-Hing
Posts: 2
Joined: Mon Nov 07, 2022 1:52 pm

Using OpenSim Python on M1 Mac Silicon

Post by Victor Ng-Thow-Hing » Wed Dec 28, 2022 11:41 am

Hi SimTK people!

I'm trying to use the OpenSim Python libraries with the native Python that comes with my M1 Mac laptop.
When I try to `import opensim as osim`, I get an error:

Code: Select all

Python 3.10.9 (main, Dec 15 2022, 17:11:09) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin

ImportError: dlopen(/Applications/OpenSim 4.4/sdk/Python/opensim/_simbody.so, 0x0002): tried: '/_simbody.so' (no such file), '/Applications/OpenSim 4.4/sdk/lib/_simbody.so' (no such file), '/Applications/OpenSim 4.4/sdk/Python/opensim/_simbody.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Applications/OpenSim 4.4/sdk/Python/opensim/_simbody.so' (no such file), '/Applications/OpenSim 4.4/sdk/Python/opensim/_simbody.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/_simbody.so' (no such file), '/Applications/OpenSim 4.4/sdk/lib/_simbody.so' (no such file), '/Applications/OpenSim 4.4/OpenSim 4.4.app/Contents/Resources/opensim/sdk/Python/opensim/_simbody.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Applications/OpenSim 4.4/OpenSim 4.4.app/Contents/Resources/opensim/sdk/Python/opensim/_simbody.so' (no such file), '/Applications/OpenSim 4.4/OpenSim 4.4.app/Contents/Resources/opensim/sdk/Python/opensim/_simbody.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
)

I believe this is because the .so libraries were build on an intel-based Mac (x86_64) but I need the libraries built for Mac silicon (arm64). Is it possible to get Mac Silicon libraries built? I tried to build from source, but the build script stopped because I don't have Matlab installed. Is there a way to build without the Matlab dependencies?

Regards,
Victor

Tags:

User avatar
Carmichael Ong
Posts: 371
Joined: Fri Feb 24, 2012 11:50 am

Re: Using OpenSim Python on M1 Mac Silicon

Post by Carmichael Ong » Wed Jan 18, 2023 12:40 pm

It does indeed look like there's a mix in the architecture. A few thoughts:

1. You can install Python executables that are x64 rather than ARM to see if that fixes the issue.
2. OpenSim now has a conda package (https://anaconda.org/opensim-org/opensim) that will help with installing Python in a conda environment. Note that there are no arm builds yet, so you will still have to have an environment that is x64 first.
3. There's a development branch that's a little stale that can build arm libraries, but the installation step isn't fixed yet (https://github.com/opensim-org/opensim-core/pull/3192). This has only been tested with the two flags DBUILD_PYTHON_WRAPPING=OFF and DBUILD_JAVA_WRAPPING=OFF. Turning off the java wrapping will build without matlab dependencies.

POST REPLY