OpenSim API Python Import Error: Library not loaded

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
P Wesberg
Posts: 10
Joined: Fri Jan 11, 2019 5:55 am

OpenSim API Python Import Error: Library not loaded

Post by P Wesberg » Wed Aug 07, 2019 9:13 am

Dear All,

I try to work with the OpenSim python wrapping. To run OpenSim-core-installation via python3 wrapping in an anaconda environment I installed OpenSim-Core following the procedure for MacOS with superbuild using Cmake and Xcode. The following problem occurs trying to import opensim:

Code: Select all

ImportError: dlopen(/Applications/anaconda3/envs/simenv/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/_simbody.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.7/Python
The folder "/Library/Frameworks/Python.framework/Versions/3.7/Python" does not exist. I think it should points to the Anaconda Python instead?
But maybe this is a wrong interpretation of this error report :-)

Please help!
Thanks a lot, Philippe

complete error code:

Code: Select all

(simenv) ip184103:~ philippewesberg$ python
Python 3.7.3 (default, Mar 27 2019, 16:54:48) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import opensim
Traceback (most recent call last):
  File "/Applications/anaconda3/envs/simenv/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/simbody.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "/Applications/anaconda3/envs/simenv/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 670, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 583, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1043, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: dlopen(/Applications/anaconda3/envs/simenv/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/_simbody.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.7/Python
  Referenced from: /Applications/anaconda3/envs/simenv/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/_simbody.so
  Reason: image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Applications/anaconda3/envs/simenv/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/__init__.py", line 1, in <module>
    from .simbody import *
  File "/Applications/anaconda3/envs/simenv/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/simbody.py", line 17, in <module>
    _simbody = swig_import_helper()
  File "/Applications/anaconda3/envs/simenv/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/simbody.py", line 16, in swig_import_helper
    return importlib.import_module('_simbody')
  File "/Applications/anaconda3/envs/simenv/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_simbody'
>>> 

Tags:

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: OpenSim API Python Import Error: Library not loaded

Post by jimmy d » Wed Aug 07, 2019 10:50 am

Just to be clear, you are building OpenSim from source using the instructions found here?

Did you open the CMake GUI and check which Python path that your system is using to build against?

If you are using Mac, did you set your Python path correctly? Have you checked in Terminal by using 'which python'?

User avatar
P Wesberg
Posts: 10
Joined: Fri Jan 11, 2019 5:55 am

Re: OpenSim API Python Import Error: Library not loaded

Post by P Wesberg » Wed Aug 14, 2019 7:01 am

Dear James,

Yes, I've used the instructions you mentioned https://github.com/opensim-org/opensim-core as well as these for further settings https://simtk-confluence.stanford.edu:8 ... xvsPython3

In the CMake GUI I specified OPENSIM_python_version to 3. I don't See the option to specify the python path in the CMake GUI. But the environment shows the right path to anaconda python 3.7:

Code: Select all

Last login: Wed Aug 14 15:52:54 on ttys000
(base) ip184103:~ philippewesberg$ conda activate simenv
(simenv) ip184103:~ philippewesberg$ type -a python
python is /Applications/anaconda3/envs/simenv/bin/python
python is /usr/bin/python
(simenv) ip184103:~ philippewesberg$ python
Python 3.7.3 (default, Mar 27 2019, 16:54:48) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
PS: the first path which is printed using 'type -a python' is identically to what is printed by 'which python'

thanks for your help!

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: OpenSim API Python Import Error: Library not loaded

Post by Ayman Habib » Thu Aug 15, 2019 1:59 pm

Hello,

In CMake GUI, if you enable view of Advanced options (checkbox) then you should see "PYTHON_EXECUTABLE", make sure that it points to the python that you intend to use. In general we build/test against standard python from python.org and not custom installations (e.g. Anaconda) which may introduce other unknowns.

Please let us know what you find out.

Best regards,
-Ayman

User avatar
P Wesberg
Posts: 10
Joined: Fri Jan 11, 2019 5:55 am

Re: OpenSim API Python Import Error: Library not loaded

Post by P Wesberg » Mon Sep 02, 2019 8:44 am

Hello,

Dear Ayman, thanks a lot for your help. I didn't check the advanced option and didn't specify the link in the prior installation process, which was definitely a mistake. So I was able to solve the problem former error by linking the PYTHON_EXECUTABLE to the python executable in the anaconda environment Applications/anaconda3/envs/simenv/bin/python3.7

Unfortunately now there occurs another error "SEGFAULT". Running the test in XCode

Code: Select all

The following tests FAILED:
	 92 - python_tests (SEGFAULT)
	 93 - python_examples (SEGFAULT)
Errors while running CTest
make: *** [/Users/philippewesberg/Documents/opensim/opensim-core-build/CMakeFiles/RUN_TESTS_PARALLEL] Error 8
Command /bin/sh failed with exit code 2
(Nevertheless I've installed OpenSim-Core and also set the path variables in the bash-profile and installed the setup.py coming with the opensim installation. Trying to run opensim via python in the terminal resulted Segmentation fault: 11 Probably the same problem as in the test.

Code: Select all

(simenv) ip184103:~ philippewesberg$ python
Python 3.7.4 (default, Aug 13 2019, 15:17:50) 
>>> import opensim as osim
Segmentation fault: 11

User avatar
P Wesberg
Posts: 10
Joined: Fri Jan 11, 2019 5:55 am

Re: OpenSim API Python Import Error: Library not loaded

Post by P Wesberg » Wed Nov 27, 2019 7:11 am

Hello,

I'm struggling to use the OpenSim Python API on my MacOS. The following error occurs:

Code: Select all

>>> import opensim as osim
Traceback (most recent call last):
  File "/Applications/anaconda3/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/simbody.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "/Applications/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 670, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 583, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1043, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: dlopen(/Applications/anaconda3/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/_simbody.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.7/Python
  Referenced from: /Applications/anaconda3/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/_simbody.so
  Reason: image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Applications/anaconda3/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/__init__.py", line 1, in <module>
    from .simbody import *
  File "/Applications/anaconda3/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/simbody.py", line 17, in <module>
    _simbody = swig_import_helper()
  File "/Applications/anaconda3/lib/python3.7/site-packages/opensim-4.0-py3.7.egg/opensim/simbody.py", line 16, in swig_import_helper
    return importlib.import_module('_simbody')
  File "/Applications/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_simbody'
The library which could not be loaded
2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.7/Python
does not exist at all.
I use the anaconda python installation.
I used brew to install simbody.

PS: I'm not a programmer. If possible, please help me with detailed instructions.

best regards, Philippe

User avatar
Dan Nicolella
Posts: 1
Joined: Sun Apr 11, 2010 12:25 pm

Re: OpenSim API Python Import Error: Library not loaded

Post by Dan Nicolella » Mon Apr 20, 2020 8:34 am

Hi,

We are running into the same issue (segfault) when trying to install the python API on an MacOS system using the Anaconda python 3.7 installation. We've tried building OpenSIm from source using the superbuild instructions. Everything seems to build and install without errors, but the python test fails: (output from ctest command)
98% tests passed, 2 tests failed out of 106

Total Test time (real) = 230.00 sec

The following tests FAILED:
94 - python_tests (SEGFAULT)
95 - python_examples (SEGFAULT)
Errors while running CTest

We also get a segfault when attempting to import opensim within python:

Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import opensim
Segmentation fault: 11

Any help would be appreciated.

Thanks in advance.
Best Regards,
Dan Nicolella

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: OpenSim API Python Import Error: Library not loaded

Post by Ayman Habib » Mon Apr 20, 2020 9:54 am

Hello,

Two questions:
1. Can you try the python.org python and our distribution (4.1) that was compiled and tested with this specific python 3.7 (instructions here https://simtk-confluence.stanford.edu:8 ... +in+Python)? Let us know if/how that works.
2. If you must build from source, please indicate what source you're using, make sure your Anaconda python is used for the build, DYLD_LIBRARY_PATH is set, and if you continue to have problems send a stack trace so we can help you troubleshoot.

Hope this helps,
-Ayman

User avatar
Laura Healey
Posts: 2
Joined: Fri Apr 17, 2020 9:59 am

Re: OpenSim API Python Import Error: Library not loaded

Post by Laura Healey » Wed Apr 29, 2020 9:16 am

Hi there,

I am having a similar problem and I am unable to get opensim 4.1 to import into Python 3.7 (using anaconda)

I am not sure what you mean by use the python.org python, although I followed the steps in the instructions you posted. I think my problem arises from not setting the DYLD_LIBRARY_PATH properly. I am using

Code: Select all

$ export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:<OPENSIM_INSTALL_DIR>/lib
as shown in the tutorial.

Code: Select all

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:'~/Applications/OpenSim 4.1/lib'
But I am getting an error when I try to import opensim in python

Code: Select all

  File "<ipython-input-1-3a6040a397f9>", line 1, in <module>
    import opensim

  File "/opt/anaconda3/lib/python3.7/site-packages/opensim-4.1-py3.7.egg/opensim/__init__.py", line 1, in <module>
    from .simbody import *

  File "/opt/anaconda3/lib/python3.7/site-packages/opensim-4.1-py3.7.egg/opensim/simbody.py", line 28, in <module>
    _simbody = swig_import_helper()

  File "/opt/anaconda3/lib/python3.7/site-packages/opensim-4.1-py3.7.egg/opensim/simbody.py", line 24, in swig_import_helper
    _mod = imp.load_module('_simbody', fp, pathname, description)

  File "/opt/anaconda3/lib/python3.7/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)

  File "/opt/anaconda3/lib/python3.7/imp.py", line 342, in load_dynamic
    return _load(spec)

ImportError: dlopen(/opt/anaconda3/lib/python3.7/site-packages/opensim-4.1-py3.7.egg/opensim/_simbody.so, 2): Library not loaded: @rpath/libosimTools.dylib
  Referenced from: /opt/anaconda3/lib/python3.7/site-packages/opensim-4.1-py3.7.egg/opensim/_simbody.so
  Reason: image not found
Am I missing a step somewhere?

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: OpenSim API Python Import Error: Library not loaded

Post by Ayman Habib » Wed Apr 29, 2020 10:17 am

Hi Laura,

There are multiple python distributions and it's unclear if these are all compatible (and on what platforms ). We build and publish our releases using the distribution of python from https://www.python.org/. Anaconda is another distribution. I don't know if other users were able to use our python interface with Anaconda on Macs, but if that doesn't work out of the box you could either:
1. Download/install Python from the website above (well travelled and documented route).
2. Build OpenSim from source and configure the build process to use your Anaconda python.

Please let us know what you find out se we can support our growing number of python users.

Best regards,
-Ayman

POST REPLY