OpenSim 4.1 - Install - Ubuntu 20.04

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ana de Sousa
Posts: 67
Joined: Thu Apr 07, 2016 4:21 pm

OpenSim 4.1 - Install - Ubuntu 20.04

Post by Ana de Sousa » Thu Dec 03, 2020 6:16 am

Hi everyone,
I've had to install OpenSim in Ubuntu 20.04 a few times in the last couple of months, and I had a bit of a hard time installing it.
This post is just a resume of the procedure with all steps (basically command lines, I am not using the CMake GUI). I hope these notes help others!

1. Go to the root of your system and open the .bashrc file:

Code: Select all

    cd
    gedit .bashrc
2. Add these commands at the end of the file:
alias python=python3
alias swig=swig3.0
3. Save the file and close the terminal.
4. Open a new terminal and create a folder for OpenSim build:

Code: Select all

    mkdir opensim
    cd opensim
5. Update the system and install required dependencies:

Code: Select all

    sudo apt-get update
    sudo apt install build-essential
    sudo apt install python3-pip
    pip3 install numpy
    sudo apt-get --yes install -y swig3.0 git cmake cmake-curses-gui 
    sudo apt-get --yes install freeglut3-dev libxi-dev libxmu-dev liblapack-dev python-dev openjdk-8-jdk
    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
Important note: OpenSim does not build successfully with swig4. If possible, do not install this version, just swig3.0.

6. Build OpenSim dependencies:

Code: Select all

    git clone https://github.com/opensim-org/opensim-core.git
    mkdir opensim_dependencies_build
    cd opensim_dependencies_build
    cmake ../opensim-core/dependencies/ \
          -DCMAKE_INSTALL_PREFIX='~/opensim/opensim_dependencies_install' \
          -DCMAKE_BUILD_TYPE=RelWithDebInfo
    make -j8
7. Build OpenSim. This step takes a while, and my computer freezes with -j higher than 2:

Code: Select all

    cd ..
    mkdir opensim_build
    cd opensim_build
    cmake ../opensim-core \
          -DCMAKE_BUILD_TYPE=RelWithDebInfo \
          -DCMAKE_INSTALL_PREFIX='~/opensim/install' \
          -DOPENSIM_DEPENDENCIES_DIR="~/opensim/opensim_dependencies_install" \
          -DBUILD_PYTHON_WRAPPING=ON \
          -DBUILD_JAVA_WRAPPING=OFF \
          -DWITH_BTK=ON
    make -j2
8. Test and install OpenSim:

Code: Select all

    ctest -j2
    make -j2 install
9. During tests, two of them may fail (`95:python_tests`, `96:python_examples`). For fixing this, follow steps 10-12, and then test and install OpenSim again (step 8).
10. Run python setup:

Code: Select all

    cd ~/opensim/install/lib/python3.8/site-packages
    sudo python3 setup.py install
11. Change the `.bashrc`:

Code: Select all

    cd
    gedit .bashrc
12. Add the path to opensim:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/opensim/install/lib
All steps are, of course, based on opensim-core instructions: https://github.com/opensim-org/opensim- ... -makefiles

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: OpenSim 4.1 - Install - Ubuntu 20.04

Post by Dimitar Stanev » Sat Dec 05, 2020 11:55 am

Hi Ana,

I have a short script similar to what you just outlined for Ubuntu 18.04:

Code: Select all

#!/usr/bin/env bash

set -xeuo pipefail

# install dependencies in case they are missing
# sudo apt-get --yes install git cmake cmake-curses-gui \
#                            freeglut3-dev libxi-dev libxmu-dev \
#                            liblapack-dev swig python-dev \
#                            openjdk-8-jdk

try_clone_checkout() {
    url="${1}"
    ref="${2}"

    dir=$(basename "${url}" | sed 's/.git$//')

    echo "${0}: ${dir}: must be built from source for Linux builds"
    if [ ! -d "${dir}" ]; then
        git clone "${url}"
        cd "${dir}"
        git checkout "${ref}"
        cd -
    else
        echo "${0}: ${dir}: already exists: skipping clone"
    fi
}

# clone repo
try_clone_checkout "https://github.com/mitkof6/opensim-core.git" "bindings_timestepper"

# build dependencies
cd opensim-core
mkdir build_dependencies
cd build_dependencies
cmake ../dependencies/ \
      -DCMAKE_INSTALL_PREFIX='../install/dependencies' \
      -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

# build opensim-core
cd ..
mkdir build_opensim
cd build_opensim
cmake .. \
      -DCMAKE_INSTALL_PREFIX="../install/" \
      -DCMAKE_BUILD_TYPE=Release \
      -DOPENSIM_DEPENDENCIES_DIR="../install/dependencies" \
      -DSIMBODY_HOME="../install/dependencies/simbody" \
      -DBUILD_PYTHON_WRAPPING=ON \
      -DOPENSIM_PYTHON_VERSION=3 \
      -DBUILD_API_EXAMPLES=OFF \
      -DBUILD_TESTING=OFF \
      -DWITH_BTK=ON
make -j$(nproc)
make install

Please check out the mainstream repository of opensim-core and not my version. Here are some instructions:

Code: Select all

## OpenSim (Ubuntu 18.04)

For this to work, we currently maintain a custom version of `opensim-core` until
some of the fixes are included in the mainstream branch. For you to build this,
you can run the script provided in this repository:

`build_opensim-core`

This will build and install OpenSim libraries in the install folder inside
`opensim-core`. In the future, we will provide a pre-built version for
convenience. After building OpenSim, configure the environmental variables as
follows:

```shell
export OPENSIM_HOME=/path-to-filesystem/opensim-core
export OpenSim_DIR=$OPENSIM_HOME/lib/cmake/OpenSim
export LD_LIBRARY_PATH=$OPENSIM_HOME/lib:$LD_LIBRARY_PATH
export PATH=$OPENSIM_HOME/bin:$PATH
export PATH=$OPENSIM_HOME/libexec/simbody:$PATH
```

The Python bindings are built with the system Python version (substitute X.X
below). To install run:

```shell
cd $OPENSIM_HOME/lib/pythonX.X/site-packages
python3 setup.py install --user
```
To test the Python bindings try importing OpenSim in Python3:

```
cd ~
python3 -c "import opensim"
```

Sometimes the above command fails. The `opensim` folder that is created in
`$OPENSIM_HOME/lib/pythonX.X/site-packages` after running `python3 setup.py
install --user` may not be properly copied in the Python `site-packages`. In
that case, you can copy it manually.

```
cd -rf $OPENSIM_HOME/lib/pythonX.X/site-packages/opensim ~/.local/lib/pythonX.X/site-packages
```


User avatar
Ana de Sousa
Posts: 67
Joined: Thu Apr 07, 2016 4:21 pm

Re: OpenSim 4.1 - Install - Ubuntu 20.04

Post by Ana de Sousa » Mon Dec 07, 2020 12:19 pm

Excellent, thanks, Dimitar.

My final intention was to install opensim in a docker environment for then use Travis to build and test the code beforehand. I wanted to create a clean script like yours, but I got stuck in some steps. And didn't have time to go further on that yet.

User avatar
trung phan
Posts: 1
Joined: Mon Dec 07, 2020 12:44 am

Re: OpenSim 4.1 - Install - Ubuntu 20.04

Post by trung phan » Sun Jan 10, 2021 9:51 am

Please explain to me this error. Thank you very much.

(gt37) lab@lab-System-Product-Name:~/opensim/install/lib/python3.7/site-packages$ sudo python3 setup.py install
[sudo] password for lab:
Traceback (most recent call last):
File "setup.py", line 6, in <module>
from setuptools import setup
ModuleNotFoundError: No module named 'setuptools'

User avatar
Ana de Sousa
Posts: 67
Joined: Thu Apr 07, 2016 4:21 pm

Re: OpenSim 4.1 - Install - Ubuntu 20.04

Post by Ana de Sousa » Thu Apr 01, 2021 5:31 am

Hi @trung phan,

I am not sure, but the first thing I would try is to find the setup.py in your opensim/install libraries.

POST REPLY