Page 1 of 2
OpenSim Python Scripting
Posted: Tue Feb 14, 2023 10:47 am
by albornomazen
Hi Everyone,
I'm trying to install OpenSim 4.4 with Python scripting with anaconda (instructions here:
https://simtk-confluence.stanford.edu:8 ... +in+Python).
My python version is 3.8.16. When I do import opensim in python,. I get the following error:
import opensim as osim
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/OpenSim 4.4/OpenSim 4.4.app/Contents/Resources/opensim/sdk/Python/opensim/__init__.py", line 9, in <module>
from .simbody import *
File "/Applications/OpenSim 4.4/OpenSim 4.4.app/Contents/Resources/opensim/sdk/Python/opensim/simbody.py", line 13, in <module>
from . import _simbody
ImportError: dlopen(/Applications/OpenSim 4.4/OpenSim 4.4.app/Contents/Resources/opensim/sdk/Python/opensim/_simbody.so, 0x0002): symbol not found in flat namespace '_PyCMethod_New'
My DYLD_LIBRARY_PATH is set to: :/Applications/OpenSim 4.4/sdk/lib:/Applications/OpenSim 4.4/sdk/Simbody/lib
If you have ideas what could be wrong, I'd appreciate it.
all the best,
Mazen
Re: OpenSim Python Scripting
Posted: Tue Feb 14, 2023 11:03 am
by aymanh
Hi Mazen,
Starting python 3.8 loading of dynamic libraries stopped relying on library path unless you specifically indicate that preference.
We now recommend using conda/Anaconda instead of reusing the libraries from the application as it appears to be the case based on the error message. I'd make sure to indicate not using the library path and then the conda installation should work out of the box. It could be an issue with specific Mac packages so please describe your osx version and hardware if possible to help us troubleshoot.
Thank you,
Ayman
Re: OpenSim Python Scripting
Posted: Tue Feb 14, 2023 11:22 am
by albornomazen
Thanks Ayman. If I just use conda/Anaconda instead of the libraries from the Application, I get the following error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mazen/opt/anaconda3/envs/opensim_scripting/lib/python3.8/site-packages/opensim/__init__.py", line 9, in <module>
from .simbody import *
File "/Users/mazen/opt/anaconda3/envs/opensim_scripting/lib/python3.8/site-packages/opensim/simbody.py", line 13, in <module>
from . import _simbody
ImportError: dlopen(/Users/mazen/opt/anaconda3/envs/opensim_scripting/lib/python3.8/site-packages/opensim/_simbody.so, 0x0002): Library not loaded: @rpath/libosimExampleComponents.dylib
Referenced from: /Users/mazen/opt/anaconda3/envs/opensim_scripting/lib/python3.8/site-packages/opensim/_simbody.so
Reason: tried: '/Users/mazen/opt/anaconda3/envs/opensim_scripting/lib/python3.8/site-packages/opensim/libosimExampleComponents.dylib' (no such file), '/Users/mazen/opt/anaconda3/envs/opensim_scripting/lib/python3.8/site-packages/opensim/../../../sdk/lib/libosimExampleComponents.dylib' (no such file), '/Users/runner/opensim-core-install/sdk/lib/libosimExampleComponents.dylib' (no such file), '/Users/mazen/opt/anaconda3/envs/opensim_scripting/lib/python3.8/site-packages/opensim/../../../sdk/Simbody/lib/libosimExampleComponents.dylib' (no such file), '/Users/runner/opensim-core-install/sdk/Simbody/lib/libosimExampleComponents.dylib' (no such file), '/Users/mazen/opt/anaconda3/envs/opensim_scripting/lib/python3.8/site-packages/opensim/libosimExampleComponents.dylib' (no such file), '/Users/mazen/opt/anaconda3/envs/opensim_scripting/lib/python3.8/site-packages/opensim/../../../sdk/lib/libosimExampleComponents.dylib' (no such file), '/Users/runner/opensim-core-install/sdk/lib/libosimExampleComponents.dylib' (no such file), '/Users/mazen/opt/anaconda3/envs/opensim_scripting/lib/python3.8/site-packages/opensim/../../../sdk/Simbody/lib/libosimExampleComponents.dylib' (no such file), '/Users/runner/opensim-core-install/sdk/Simbody/lib/libosimExampleComponents.dylib' (no such file), '/Users/mazen/opt/anaconda3/envs/opensim_scripting/bin/../lib/libosimExampleComponents.dylib' (no such file), '/Users/mazen/opt/anaconda3/envs/opensim_scripting/bin/../lib/libosimExampleComponents.dylib' (no such file), '/usr/local/lib/libosimExampleComponents.dylib' (no such file), '/usr/lib/libosimExampleComponents.dylib' (no such file)
I'm on the Macbook pro 2021 (M1 pro chip) using Monterey (12.3).
Thanks,
Mazen
Re: OpenSim Python Scripting
Posted: Tue Feb 14, 2023 2:15 pm
by aymanh
Hi Mazen,
We just tried installing the conda package with Python 3.8 on M1 machine (running x86_64) locally and had no issues. Keep in mind that we don't support native M1 builds. Possible differences between our environment and yours:
1- OSX 13 (worked) vs. 12.3
2- Other packages installed in your conda environment vs. ours.
3- Low level dependencies that we assume and you don't have.
For 1, we don't have access to similar environment so it would be good to hear from other users on the forum if they were successful or had issues.
For 2, you can install conda fresh (in case some leftovers from older installations are still lingering) and create a new environment, try to install opensim in it.
The last item can be checked by running otool on the offending .dylib(s) and checking if there are dependencies that can not be satisfied.
Please let us know what you find out.
-Ayman
Re: OpenSim Python Scripting
Posted: Wed Feb 15, 2023 7:50 am
by npickle
I encountered a similar issue on Windows yesterday when trying to install the OpenSim (4.4.1) package on a fresh Anaconda environment. Using the old installation method (running setup_win_python.py and pip install) failed on Python 3.8.16. However, I tried it on a Python 3.8.13 environment and it worked fine.
Ultimately I used the new conda install method (
https://anaconda.org/opensim-org/opensim) to install on Python 3.8.16 and everything is working.
Re: OpenSim Python Scripting
Posted: Thu Feb 16, 2023 2:22 pm
by albornomazen
Thanks Ayman and Nathan.
I had previously attempted to install with the instructions:
https://simtk-confluence.stanford.edu:8 ... Python-Mac
I had tried on arm, but will try again with x86_64.
I just saw these new instructions here:
https://simtk-confluence.stanford.edu:8 ... da+Package
It seems that all that is required is this line below?
conda install -c opensim-org opensim
After that, I should be able to import opensim in python without errors? Would I need to do: conda activate opensim_scripting or anything else?
Thanks,
Mazen
Re: OpenSim Python Scripting
Posted: Thu Feb 16, 2023 4:28 pm
by aymanh
Hi Mazen,
Typically conda users create environments (self-contained with specific python version) to work in, so you can create an environment with the specific python version you want, activate it then install opensim in it as described, then conda can resolve which download to get, download and install. If you don't create a separate environment then you have a default base environment with whatever default python version and opensim would be installed in that base environment. It's up to you.
Please let us know how that works for you,
-Ayman
Re: OpenSim Python Scripting
Posted: Thu Feb 16, 2023 9:32 pm
by albornomazen
Thanks so much Ayman, installing opensim worked.
When trying to install opensim-moco (conda install -c opensim-org opensim-moco), I constantly get the same error, even when trying different python versions (3.7, 3.8, 3.10):
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- opensim-moco -> python[version='>=2.7,<2.8.0a0|>=3.8,<3.9.0a0|>=3.6,<3.7.0a0|>=3.5,<3.6.0a0']
- opensim-moco -> python[version='>=3.7,<3.8.0a0']
Your python: python=3.10
Mazen
Re: OpenSim Python Scripting
Posted: Fri Feb 17, 2023 11:59 am
by aymanh
Thanks for trying this out and reporting back, Mazen.
The opensim conda package comes without moco included by default. We have a separate opensim-moco package that includes the moco libraries and their extensive list of dependencies but this is available only on windows (per the downloads page
https://anaconda.org/opensim-org/opensim-moco/files). There's an archaic version (0.4) of the same package on osx that goes back 2 years ago so there's no surprise it's having issues with the latest python.
We're in the process of creating the opensim-moco packages for osx and linux though this has been complicated by the switch to M1 by Apple which adds another wrinkle.
I created an issue on github to track
https://github.com/opensim-org/conda-opensim/issues/27
Sorry about the confusion regarding moco,
Best regards,
-Ayman
Re: OpenSim Python Scripting
Posted: Sun Mar 12, 2023 10:41 pm
by albornomazen
Thanks a lot Ayman.
I tried installing OpenSim on Mac (with Rosetta on an M1) with conda (conda install -c opensim-org opensim) on a student computer, however, when importing opensim in python, I got the error: "no module named opensim". If you have an idea on what could have caused this, please let me know.
all the best,
Mazen