opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
778 stars 311 forks source link

ModuleNotFoundError: No module named 'opensim' #3124

Closed csas8682 closed 1 year ago

csas8682 commented 2 years ago

Hello,

I am trying to build the OpenSim API with the - For the impatient (Windows) - build instruction. When I run the tests

ctest --build-config RelWithDebInfo --parallel 8

it passes all tests except:

Hence I would like to use opensim in Python it does not bother me furhter, that it fails the Matlab tests. But when i try to run the Python-Examples (build_simple_arm_model.py) in Spyder, I always get

import opensim Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'opensim'.

I added the _C:\Users\opensiminstall\bin as path variable (both, to System-Path and PYTHONPATH), but when I use the conda list command, opensim is not listed.

The thing I do not understand is, how it can pass test _121 Test: python_examples_, but further I cannot use or find it in my python environment. Any idea or help would be very helpfull and I would appreciate it a lot! As I said, I am trying to build it for a few days now and do not know what else I could do! Thank you very much in advance!

LastTestsFailed.log

aymanhab commented 2 years ago

The main issue is that python_tests run on build environment while typically you run python in installed environment that has a different layout. We work around that by setting PYTHONPATH in the build script but in installed environment we try to avoid that to make our python package act similar to other packages. Hope this explains but please feel free to propose ways to improve the documentation or layout as needed.

csas8682 commented 2 years ago

Okay thank you for your reply! 🙏 I think I kind of understand it, to be honest I am quite new and not that experienced yet to computer sience... So I still have some further questions and problems:

I tried to build and install OpenSim with Visual Studios now, everything went well, I failed the same tests as with the impatient method, and when I try to run the build-simple-arm-model.py example in Spyder I still get the same ModuleNotFoundError: No module named 'opensim'.

After adding the following code:

import sys
osim_path = 'D:/Dokumente/Programme/OpenSim/opensim-core/sdk/Python'
sys.path.insert(0,osim_path)
import opensim as osim

I do not get the Error any more, but do not get any results neither. Spyder prints the following:

[info] 'biceps' Parameter update for the damped-model: ActiveForceLengthCurve minimum value was 0.1 but is now 0.0. Windows fatal exception: access violation Main thread: Current thread 0x000014cc (most recent call first): File "D:/Dokumente/Programme/OpenSim/opensim-core/sdk/Python\opensim\simulation.py", line 18666 in initialize File "C:\Users\anaconda3\envs\python37\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 465 in exec_code File "C:\Users\anaconda3\envs\python37\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 578 in runfile File "C:\Users\Vinzenz\AppData\Local\Temp/ipykernel_15620/3176381764.py", line 1 in Restarting kernel...

And Simbody 3.8: python pops up in a new window, but is completly blank:

SimBody

Further when i run, the conda list command in my conda environment OpenSim is not listed, even though I tried to add it to my path.

How can I add OpenSim to my anaconda environment, so that it would be listed in the conda list command and how can I run the given example build-simple-arm-model.py so that I get the expected result, as shown in the documentation?

Sorry for the maybe "stupid" questions, and thank you for your help and time in advance! 🙏

aymanhab commented 2 years ago

Did you try to install following the instructions here https://simtk-confluence.stanford.edu/display/OpenSim/Scripting+in+Python If so you're running from installed environment and you should see opensim in spyder.

Generally, to have opensim available in your conda environment it has to be installed into the python distribution under your conda.

jenhicks commented 1 year ago

Please re-open if this is still causing issues.

JesusOlivaresJ commented 1 year ago

Good morning,

I have been trying for a couple of weeks analysing some videos I filmed with the football team I work with, but I have been not able to conduct such analyses.

I followed the instructions on https://github.com/stanfordnmbl/opencap-processing. Apparently, everything goes fine in the Install Requirements part, but when I try to run the Examples it looks like my Python (I am using spyder to run the scripts) is not able to find the modules (opensim, utilskinematics, etc.)

I tried the solutions here provided, and many others I found in the cloud... and nothing. I understand some basics of programming because I have already worked with R, but I feels like I do not understand quite well the logics behind Python. Specifically, as suggested by @aymanhab I followed the instructions to solve the problem here https://simtk-confluence.stanford.edu:8443/display/OpenSim/Scripting+in+Python. In the Step-by-step instructions when using Anaconda with OpenSim 4.3+ (because my version of OpenSim is 4.4), I am not been able to find a folder called similarly to OpenSim\4.3\Code\Python as suggested. The only I found is that C:\Users\jesus\anaconda3\pkgs\opensim-4.4-py39np120 or that C:\Users\jesus\anaconda3\envs\opencap-processing\Lib\opensim, but looks like none of them are what I am looking for. Again, I think that there is something in Python's logic I am missing.

My Python version is 3.9, from Anaconda is Anaconda3 (Python 3.10.9 64-bit) and the version of OpenSim installed is opensim-org opensim=4.4=py39np120. I installed also Visual Studio Community 2022.

I am sorry if my question is not really good formulated, but not sure what the problem is and how I could best report. Thank you in advance for your attention.

aymanhab commented 1 year ago

For conda type of installation we updated the documentation page, please do the one line install described there and on anaconda.org. make sure you either manually pick the correct python version or have a conda environment with same python version expected by opencap. If that doesn't work please open a new issue with your specific use case so we can investigate.

JesusOlivaresJ commented 1 year ago

For conda type of installation we updated the documentation page, please do the one line install described there and on anaconda.org. make sure you either manually pick the correct python version or have a conda environment with same python version expected by opencap. If that doesn't work please open a new issue with your specific use case so we can investigate.

Hi @aymanhab, thank you for your reply. Please, could you send me the link of the documentation page? Thank you so much.

aymanhab commented 1 year ago

Here you go https://simtk-confluence.stanford.edu/display/OpenSim/Scripting+in+Python there's a notice on top regarding conda

JesusOlivaresJ commented 1 year ago

Great, thank you so much!