OpenSim Python Scripting

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Carmichael Ong
Posts: 375
Joined: Fri Feb 24, 2012 11:50 am

Re: OpenSim Python Scripting

Post by Carmichael Ong » Mon Mar 13, 2023 3:56 pm

Here are steps that work on my M1 machine using miniconda, on OSX 13.2.1

Create, activate, and install opensim in new environment (this worked for me with 3.7, 3.8, 3.9, 3.10)

Code: Select all

conda create -n opensim_py38 python=3.8
conda activate opensim_py38
conda install -c opensim-org opensim
Then when I launch python (typing 'python' in the terminal window), 'import opensim' works for me with no errors.

I could replicate the "no module" issue, but only if I tried python 3.11. This I think makes sense since there is no python 3.11 build on conda yet: https://anaconda.org/opensim-org/opensim/files

User avatar
Mazen Al Borno
Posts: 10
Joined: Fri Jan 27, 2023 2:19 pm

Re: OpenSim Python Scripting

Post by Mazen Al Borno » Mon Mar 13, 2023 8:18 pm

Thanks Carmichael. These exact lines you posted did not work with me ("No module name opensim" error). However, it is with osx 12.3.

I was able to fix the problem with the student's computer by adding these lines:
import sys
osim_path = 'D:/Dokumente/Programme/OpenSim/opensim-core/sdk/Python'
sys.path.insert(0,osim_path)
import opensim as osim

all the best,

Mazen

User avatar
Mohammadreza Rezaie
Posts: 361
Joined: Fri Nov 24, 2017 12:48 am

Re: OpenSim Python Scripting

Post by Mohammadreza Rezaie » Sat Apr 08, 2023 11:08 am

Hi, I'm a windows user with Python 3.9.16. When I try to install OpenSim or Moco via conda, wrong build (py38np120) would be installed and finally, the same error ("No module name opensim")
My fix was to, first, ask conda to look for all available opensim versions and builds:

Code: Select all

conda search -c opensim-org opensim
Which prints:

Code: Select all

Loading channels: done
# Name		Version		Build		Channel
opensim		4.4		py37np120	opensim-org
opensim		4.4		py38np120	opensim-org
opensim		4.4		py39np120	opensim-org
Then, follow this template and install the correct build:
conda install -c <channel> <package_name>=<version>=<build_string>

Code: Select all

conda install -c opensim-org opensim=4.4=py39np120
Hope this helps,
Mohammadreza

User avatar
Jia Na
Posts: 1
Joined: Sat Nov 20, 2021 1:52 am

Re: OpenSim Python Scripting

Post by Jia Na » Tue Apr 11, 2023 4:55 am

Thanks Mohammadreza. I finally solve the by combining Mohammadreza and Carmichael's experience.

Here are my solution:

Mac M1 13.2.1
python 3.8.8

step1&2&3:

Code: Select all

conda create -n opensim_py38 python=3.8
conda activate opensim_py38
conda search -c opensim-org opensim
then you can see:

Code: Select all

Loading channels: done
# Name                       Version           Build  Channel             
opensim                        0.1.0  py37hf15cd22_1  opensim-org         
opensim                          4.4      py310np121  opensim-org         
opensim                          4.4       py37np121  opensim-org         
opensim                          4.4       py38np121  opensim-org         
opensim                          4.4       py39np120  opensim-org         
opensim                          4.4       py39np121  opensim-org         
step4:
install opensim according to your python version, here I choose py38np121

Code: Select all

conda install -c opensim-org opensim=4.4=py38np121
--------finish installation-------
all the best,
Jia

User avatar
Mazen Al Borno
Posts: 10
Joined: Fri Jan 27, 2023 2:19 pm

Re: OpenSim Python Scripting

Post by Mazen Al Borno » Wed Apr 12, 2023 1:01 pm

Thanks Mohammadreza and Jia.

Just a question for the community: I have two students (one on Mac M1 and one on Windows) where they have successfully installed Opensim on their computers, but the Simbody GUI does not show up when running their code (after "model.setUseVisualizer(True)"). I remember seeing this before, but don't remember the fix...

all the best,

Mazen

POST REPLY