Link OpenSim 4.1 to Python Scripting (ImportError; Library Not Loaded)

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ton Leenen
Posts: 17
Joined: Tue Apr 07, 2020 3:16 am

Link OpenSim 4.1 to Python Scripting (ImportError; Library Not Loaded)

Post by Ton Leenen » Thu Jun 04, 2020 8:05 am

Dear all,

I am trying to link the OpenSim 4.1 to Python 3.7 according to the required steps presented on https://simtk-confluence.stanford.edu:8 ... +in+Python, but unfortunately I get an error when importing OpenSim package. I have presented the complete code and the error in the picture below. I have tried to simply copy and past the library files into the known folder, but that only works for the errors for loading the library files. Hereafter a new similar kind of error pops up. What can I do to fix this problem?

Image

Tags:

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

Re: Link OpenSim 4.1 to Python Scripting (ImportError; Library Not Loaded)

Post by Ayman Habib » Thu Jun 04, 2020 10:20 am

Hi Ton,

The problem is specific to using Anaconda on OSX since it links the python interpretter in a specific way inconsistent with other distributions or platforms. We have a fix to handle that in our development environment that will be available in the next release but for the time being you can use the python distribution from python.org and let us know if you continue to have problems.

Best regards,
-Ayman

User avatar
Ton Leenen
Posts: 17
Joined: Tue Apr 07, 2020 3:16 am

Re: Link OpenSim 4.1 to Python Scripting (ImportError; Library Not Loaded)

Post by Ton Leenen » Thu Jun 04, 2020 10:47 am

Hi Ayman,

I have removed the Anaconda distribution from my Mac and installed the basic system Python interpreter version 3.7, but unfortunately I am still receiving a similar same error! The '@rpath/libSimTKsimbody.3.8.dylib' was not loaded when I used the Anaconda distribution, but when I changed to the basic system interpreter the '@rpath/libosimTools.dylib' was not loaded. I have to admit that something changed, but it is still not working. In the forum more people encountered these issues and rebuilding OpenSim with the source code was not working either. Are there other things I could try to get things going?

I have added a picture of the code with the error below!

Image

Beste regards,

Ton

User avatar
Ton Leenen
Posts: 17
Joined: Tue Apr 07, 2020 3:16 am

Re: Link OpenSim 4.1 to Python Scripting (ImportError; Library Not Loaded)

Post by Ton Leenen » Thu Jun 04, 2020 1:21 pm

In the meantime I have been trying to rebuild OpenSim with the source code (see image below), but I am not able to run all the code lines without getting any errors. Running the following code provides me with multiple errors (unable to find MATLAB, unable to find numpy).

Code: Select all

cmake ../opensim-core \
      -DCMAKE_INSTALL_PREFIX="~/opensim_install" \
      -DCMAKE_BUILD_TYPE=RelWithDebInfo \
      -DBUILD_PYTHON_WRAPPING=ON \
      -DBUILD_JAVA_WRAPPING=ON \
      -DOPENSIM_DEPENDENCIES_DIR="~/opensim_dependencies_install" \
      -DWITH_BTK=ON
Image
Last edited by Ton Leenen on Fri Jun 05, 2020 1:15 am, edited 1 time in total.

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

Re: Link OpenSim 4.1 to Python Scripting (ImportError; Library Not Loaded)

Post by Ayman Habib » Thu Jun 04, 2020 1:50 pm

Hello,

- You can turn off JAVA_WRAPPING as unnecessary since your goal is to use python and not Java or Matlab
- Are you using latest code on master? if not please do.
- make sure you use SWIG version 3.0.x rather than 4.x as this is not supported,
- point CMake to use the installation of python you're planning to run with.
- you need to install numpy into your python environment, otherwise cmake will fail.

Please let us know how that goes,
-Ayman

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

Re: Link OpenSim 4.1 to Python Scripting (ImportError; Library Not Loaded)

Post by Christopher Dembia » Thu Jun 04, 2020 4:51 pm

You may still be able to use the Python package that comes with OpenSim 4.1. Try using that Python package without installing it into Anaconda. Instead, try the following in a bash shell (from any directory):

Code: Select all

export PYTHONPATH=/Applications/OpenSim\ 4.1/sdk/Python
/Users/ajrleenen/opt/anaconda3/bin/python -c "import opensim"
My hope is that this would not produce an error. If it does, then follow Ayman's instructions for building from source.

An alternative: try using the OpenSim Moco python package on Anaconda, which includes OpenSim:

Code: Select all

conda install --channel conda-forge --channel opensim-org opensim-moco
https://anaconda.org/opensim-org/opensim-moco

User avatar
Ton Leenen
Posts: 17
Joined: Tue Apr 07, 2020 3:16 am

Re: Link OpenSim 4.1 to Python Scripting (ImportError; Library Not Loaded)

Post by Ton Leenen » Fri Jun 05, 2020 1:11 am

Hello Christopher Dembia,

Thanks you for you quick reply! Unfortunately, I receive the same error when I use the following code!

Code: Select all

export PYTHONPATH=/Applications/OpenSim\ 4.1/sdk/Python
/Users/ajrleenen/opt/anaconda3/bin/python -c "import opensim"
The error type is every time the same, although the path or file after the statement 'Library not loaded' is different!

Code: Select all

ImportError: dlopen(/Applications/OpenSim 4.1/sdk/Python/opensim/_simbody.so, 2): Library not loaded: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/Python
  Referenced from: /Applications/OpenSim 4.1/OpenSim 4.1.app/Contents/Resources/OpenSim/sdk/Python/opensim/_simbody.so
  Reason: image not found

User avatar
Ton Leenen
Posts: 17
Joined: Tue Apr 07, 2020 3:16 am

Re: Link OpenSim 4.1 to Python Scripting (ImportError; Library Not Loaded)

Post by Ton Leenen » Fri Jun 05, 2020 8:52 am

Hello Ayman,

I have been trying to rebuild OpenSim from the source-code, but I am running in some errors here as well which I cannot resolve on my own. I am following the extended instruction on the OpenSim Github webpage: https://github.com/opensim-org/opensim- ... sing-xcode. I am able to follow and execute all the steps in order to download and build the OpenSim dependencies. The CMake steps provides initially some errors caused by the inability to find the SWIG and Doxygen Dot executables, but these issues were resolved quite easily by finding the paths via the terminal. Hereafter, no errors occurred, although opening the Xcode project and build the BUILD_ALL provides the error presented in the the picture 1. I already tried, based on experience of users on the internet with the same error, to clean the Xcode by deleting the folders in the 'DerivedData' folder, but unfortunately these actions did not solve the error presented in picture 2. What should I do to fix this error?

Code: Select all

Last login: Fri Jun  5 17:19:13 on ttys000
ajrleenen@mbpvantonleenen ~ % type -a swig
swig is /usr/local/opt/swig@3/bin/swig
swig is /usr/local/opt/swig@3/bin/swig
ajrleenen@mbpvantonleenen ~ % type -a doxygen
doxygen is /usr/local/bin/doxygen
Picture 1
Image

Picture 2
Image

POST REPLY