Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opensim for python 3.8 #2869

Closed
mcmips opened this issue Aug 30, 2020 · 65 comments
Closed

opensim for python 3.8 #2869

mcmips opened this issue Aug 30, 2020 · 65 comments

Comments

@mcmips
Copy link

mcmips commented Aug 30, 2020

How can I get opensim to install in python 3.8 for google colab? Please help.

@aymanhab
Copy link
Member

@kidzik Can you clarify what is the workflow that's supposed to work here:

  1. What code base is used?
  2. How is it built/compiled on what platforms?
  3. How is it tested, packaged and distributed?
    @carmichaelong If you're familiar of this let me know so we can maintain collectively.

@nickbianco
Copy link
Member

Based on a recent post on the Moco forum, there may be issues with installing OpenSim in Python 3.8: https://simtk.org/plugins/phpBB/viewtopicPhpbb.php?f=1815&t=12387&p=0&start=0&view=&sid=0e54eee37b6d796a511ab14df68a3750.

Moco issue: opensim-org/opensim-moco#655.

@mcmips are you able to install on Python 3.7?

@kidzik
Copy link

kidzik commented Aug 31, 2020

There are two relatively easy ways to run OpenSim in colab.

  1. Setting up a jupyter notebook locally and connect colab to it
  2. Installing conda and opensim conda distribution in colab

Both installation methods are described here in the context of reinforcement learning with osim-rl
https://colab.research.google.com/drive/1Kbubb9_L-MDtjt0nHVYR_zF9CK1Onz4C?usp=sharing
Simbody visualizer will be available only in the first installation method.
The conda distribution that is provided in the notebook above is only available for python 3.6.

@aymanhab answering your questions:

  1. In the OpenSim conda build I was using this commit 399c8d5
  2. It was compiled with these scripts https://github.com/opensim-org/conda-opensim/tree/master/opensim on MacOS / Ubuntu / Windows. Builds are available here https://anaconda.org/kidzik/opensim/files
  3. It was built ad hoc for the NeurIPS challenge 2017 and slightly updated for 2018. There was no proper testing

It's probably good to completely scratch my builds and start off from @chrisdembia code conda-forge/staged-recipes#4693

@mcmips to answer your question, my conda builds won't work with python 3.8 so for that version you would have to recompile OpenSim. Depending what you want to do, the easiest way to make things work could be to just use conda and my OpenSim build with python 3.6

@aymanhab
Copy link
Member

@nickbianco do you know if this was specific to Anaconda or to the standard python 3.8? Trying to use Anaconda and 3.8 locally I get the errors below:
1>1: Test command: D:\anaconda3\python.exe "-m" "unittest" "discover" "--start-directory" "D:/src/opensim-core/Bindings/Python/tests" "--verbose"
1>1: Environment variables:
1>1: PATH=D:/build/opensim-core/Release
1>1: Test timeout computed to be: 10000000
1>1: D:\anaconda3\lib\site-packages\numpy_init_.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
1>1: from . import distributor_init
1>1: Traceback (most recent call last):
1>1: File "D:\anaconda3\lib\site-packages\numpy\core_init
.py", line 24, in
1>1: from . import multiarray
1>1: File "D:\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 14, in
1>1: from . import overrides
1>1: File "D:\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in
1>1: from numpy.core.multiarray_umath import (
1>1: ImportError: DLL load failed while importing multiarray_umath: The specified module could not be found.
1>1:
1>1: During handling of the above exception, another exception occurred:
1>1:
1>1: Traceback (most recent call last):
1>1: File "D:\anaconda3\lib\site-packages\numpy_init
.py", line 142, in
1>1: from . import core
1>1: File "D:\anaconda3\lib\site-packages\numpy\core_init
.py", line 50, in
1>1: raise ImportError(msg)
1>1: ImportError:
1>1:
1>1: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
1>1:
1>1: Importing the numpy C-extensions failed. This error can happen for
1>1: many reasons, often due to issues with your setup or how NumPy was
1>1: installed.
1>1:
1>1: We have compiled some common reasons and troubleshooting tips at:
1>1:
1>1: https://numpy.org/devdocs/user/troubleshooting-importerror.html
1>1:
1>1: Please note and check the following:
1>1:
1>1: * The Python version is: Python3.8 from "D:\anaconda3\python.exe"
1>1: * The NumPy version is: "1.18.5"
1>1:
1>1: and make sure that they are the versions you expect.
1>1: Please carefully study the documentation linked above for further help.
1>1:

@kidzik Does the opensim-rl environment depend on numpy? and do we need to be on 3.8? Thanks

@nickbianco
Copy link
Member

The user on the forum was using standard Python 3.8. He got an error when the Python install script tries to import the simbody Python module but was unable to find it. Module imports happen using Python's importlib, which got some minor updates in 3.8, but I've not done any debugging of my own yet.

@aymanhab
Copy link
Member

This appears to be SWIG related (release notes for SWIG 4.0.1 explicitly specifies adding support for python 3.8), so it makes no sense to try to fix this anywhere else at the moment, instead we should plan upgrading SWIG first. How time critical is this? @kidzik @nickbianco

@nickbianco
Copy link
Member

I think most users can revert to 3.7 (as did the user on the Moco forum). Unless we have users who specifically need 3.8 features it's probably not super time critical.

@kidzik
Copy link

kidzik commented Aug 31, 2020

It's not time-critical for my use cases (NeurIPS challenge and RL workshop). Also, in the tutorial I'm listing exact versions with which everything is functioning well. Numpy is indeed needed for opensim-rl. We could make it leaner and depend only on OpenSim. Our users will almost surely use numpy anyway.
So definitely it makes sense to update SWIG first.

@chrisdembia
Copy link
Member

The next release of opensim will depend on numpy.

@adamkewley
Copy link
Contributor

As an additional datapoint, I just spent a while trying to get python to work on my Windows machine for a researcher because of this issue.

The reason why I found the install pretty confusing is because using Python with OpenSim right now involves non-standard library setup steps (e.g., not using pip) and involves a few extremely specific steps, where mis-doing those steps produces a vague-sounding DLL linking error message (generated from SWIG):

  • The docs do mention python2 vs. 3 (here) but ambiguate the version when they say "set the CMake variable OPENSIM_PYTHON_VERSION to the desired version (2 or 3)". Reading it a bit more carefully clarifies that, no, it must be specifically python 3.7, not at least 3.7 (which would be assumed)
  • The python official website's officially recommended download for my Windows10 (64-bit) is 3.8.5 32-bit edition (this page, the link i got). The 64-bit edition is actually the non-default - despite 64-bit being mainstream for a decade or so. The majority of windows python users (ignoring anaconda, et. al) will install whatever that site suggests to them.
  • python setup.py install of the opensim SDK will succeed, regardless of python version or ABI - the issue only occurs when running the binary and there are no installation-time sanity checks
  • The setup also mensions editing Windows environment variables (e.g. the PATH), which I figured would be causing a runtime error (e.g. the runtime searches via the PATH), so I spent a while trying diffent PATHs
  • Switching to 3.8.5 64-bit observes almost identical error messages (slightly different, if paying attention) to using 32-bit, so it's easy to confuse the issue of the python version being incorrect with the ABI being incorrect.
  • On seeing the new error, I assumed I had mis-installed something and spent time adding debug messages into the SWIG bindings to find out why it couldn't load _simbody
  • After exhausting all of that, I eventually just switched specifically to version 3.7.8 (64-bit). This isn't an automatic assumption for python devs because the version concern usually only applies to "is it 2 or 3". Version-specific native issues are usually handled by compiling the native bindings at install time (e.g. pip will do this for source balls), or at least having the installer produce an annoying error message that explains the problem.

@adamkewley
Copy link
Contributor

To further compound the issue, after I just tried to get Anaconda working with the researcher:

  • Latest Anaconda3 now uses Python 3.8, which will not work with OpenSim 4.1. Using something like conda install python=3.7 might work, but it seems to take a very long time to run, and can subsequently explode if the user has installed a dependency that can't be cleanly downgraded to 3.7 (this was our problem--something about downgrading openssl would cause an error--so we couldn't move forward)
  • Anaconda2 (documented for OpenSim) defaults to Python2. Users then have to upgrade to 3.7. This took so long (>10 min) that I had to ditch the call, so I'm assuming that typical Anaconda users don't typically do this (instead, they use whatever the platform integrates in a particular version)
  • Because it took too long to switch the version over, we didn't have the time to try out spyder. I'm assuming that, once python is upgraded/downgraded, spyder will correctly use 3.7, but (iirc) conda can have parallel python versions, so there might be a separate configuration step required to ensure spyder then uses 3.7 after it is installed
  • From what I gathered, the reason some research teams standardize on a major Anaconda release is so that all team members can just install anaconda + libraries (via the anaconda package manager), and call it a day. The fact that OpenSim may specifically require a python downgrade and a manual installation is unlikely to go down so well with teams building software that way.

@aymanhab
Copy link
Member

Thanks for the feedback @adamkewley You have to remember that:

  1. Python changed how packages are initialized in version 3.8, the documentation was written before that change so it assumed python will maintain backward compatibility which is false in hindsight (We tested against 3.4-3.7). If you can update the documentation until we upgrade that would be great.
  2. Based on your investigation, would bindings created for python 3.8 work with 3.7 and earlier? or we have to choose between the two? Ideally we don't force users on python 3.7 and earlier to upgrade just to please 3.8 users 😸
  3. Not sure what needs to be changed on our side to use pip instead of the current mechanism, any clues?

@adamkewley
Copy link
Contributor

adamkewley commented Sep 24, 2020 via email

@adamkewley
Copy link
Contributor

As an update for this, I manually stripped all traces of other python versions from the PC and built OpenSim with anaconda's python3.8. It seems to build + install fine, but it's now having issues loading the native binaries in the .egg file that the SDK's setup.py installs to:

(base) C:\Users\ak>python
Python 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import opensim
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "C:\Users\ak\anaconda3\lib\site-packages\opensim-4.2-py3.8.egg\opensim\__init__.py", line 1, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "C:\Users\ak\anaconda3\lib\site-packages\opensim-4.2-py3.8.egg\opensim\simbody.py", line 13, in <module>
ImportError: cannot import name '_simbody' from 'opensim' (C:\Users\ak\anaconda3\lib\site-packages\opensim-4.2-py3.8.egg\opensim\__init__.py)

Which might've been similar to message I was getting when using 4.1 with python3.7, so it could be that there's some module-loading-path missing (the module is right there, in the zip package, though).

I Had similar issues with loading numpy in anaconda when configuring the custom build (to build OpenSim4.1 via anaconda /w python 3.8). To fix that, I had to set up my %PATH% with anaconda binaries etc. (e.g.). For this build of OpenSim, it seems to be that it can't load _simbody from within the .egg file the installer makes, even if my PATH is correctly occupied with opensim binaries (i can run opensim-cmd, etc.):

(base) C:\Users\ak>echo %PATH%
C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\Simbody\lib;C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\lib;C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\bin;C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install;C:\Users\ak\anaconda3;C:\Users\ak\anaconda3\Library\mingw-w64\bin;C:\Users\ak\anaconda3\Library\usr\bin;C:\Users\ak\anaconda3\Library\bin;C:\Users\ak\anaconda3\Scripts;C:\Users\ak\anaconda3\bin;C:\Users\ak\anaconda3\condabin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet;C:\Program Files\Git\cmd;C:\Program Files\MATLAB\R2020a\bin;C:\OpenSim 4.1\bin;C:\Users\ak\AppData\Local\Microsoft\WindowsApps;C:\Users\ak\.dotnet\tools;C:\Program Files\CMake\bin;C:\Program Files (x86)\NSIS\Bin;C:\Program Files (x86)\NSIS;C:\Users\ak\AppData\Local\GitHubDesktop\bin;C:\OpenSim 4.1\bin;.

However, if I use the package in its unpacked form (e.g. by manually setting PYTHONPATH=C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\python;%PYTHONPATH% so that python's module loader loads the unpacked SDK, rather than the installed egg), then it works fine:

(base) C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\Python>set PYTHONPATH=%PWD%;%PYTHONPATH%

(base) C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\Python>python
Python 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import opensim
>>>

So the trick for Anaconda /w 3.8 seems to be:

  • Install latest Anaconda
  • Ensure numpy is installed in it (it should be, by default)
  • Set up build system's PATH to be able to run Anaconda's python, ensure it definitely can import numpy
  • Build OpenSim with that populated path (it should automatically detect that python by attempting things on the PATH)
  • Install OpenSim somewhere
  • Set system PATH to the usual bin dir
  • Set system PYTHONPATH to sdk\Python
  • Don't bother running OpenSim's setup.py install

You'd think that, because the Anaconda version of OpenSim is built against 3.8, opensim would "just work" with barebones Python 3.8. But going through the exact same steps yields:

C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\Simbody\lib;C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\lib;C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files\MATLAB\R2020a\bin;C:\OpenSim 4.1\bin;C:\Users\ak\AppData\Local\Microsoft\WindowsApps;C:\Users\ak\.dotnet\tools;C:\Program Files\CMake\bin;C:\Program Files (x86)\NSIS\Bin;C:\Program Files (x86)\NSIS;C:\Users\ak\AppData\Local\GitHubDesktop\bin;C:\OpenSim 4.1\bin;
""
C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\bin;C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\Python;C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\Python\opensim
""
Python 3.8.6rc1 (tags/v3.8.6rc1:08bd63d, Sep  7 2020, 23:10:23) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import opensim
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\Python\opensim\__init__.py", line 1, in <module>
    from .simbody import *
  File "C:\Users\ak\Desktop\opensim-python38\RelWithDebInfo-install\sdk\Python\opensim\simbody.py", line 13, in <module>
    from . import _simbody
ImportError: DLL load failed while importing _simbody: The specified module could not be found.

They are slightly different versions of python, and they are built with slightly different versions of MSVC. Might be that, no idea. I installed numpy into the barebones python3.8 and it imports fine, so I don't think it's missing numpy.

It could also be because (as far as I can tell) the OpenSim build requires locating NumPy at configure time, which it probably uses it for some of the python bindings (perf?). The (working) anaconda version has the advantage of being the exact version built against with the exact numpy built against.

Either way, for my purposes, I might be able to internally ship the custom build /w instructions for using it with Anaconda as a temporary bandaid.

@dembia
Copy link

dembia commented Sep 29, 2020

@adamkewley would you be interested in picking up the work of creating an opensim conda package? This is the correct long term solution. A lot of the work is already done: conda-forge/staged-recipes#11894 . I could answer any questions you have.

@adamkewley
Copy link
Contributor

Additional update: we now have a working python3.8-based anaconda deployment of opensim internally. It seems to mostly work fine if we just hack people's bashrc computer-wide with a PYTHONPATH that points to the sdk/python dir. This probably isn't in-line with how anaconda should be used (i.e. a constrained environment pulled via its package manager), but works for us.

@aymanhab
Copy link
Member

Thanks for the update @adamkewley The main question I have is what version of SWIG you used to create the bindings and on which platforms. If you needed to make changes to get the latest source to work with python 3.8 it would be great to have these on our master branch. Did it work also with generic python 3.8 from python.org? Thank you

@adamkewley
Copy link
Contributor

@aymanhab , for our workstation's opensim (the one on which the researcher is using Anaconda /w Python 3.8):

swig3.0 -version

SWIG Version 3.0.12

Compiled with g++ [x86_64-pc-linux-gnu]

Configured options: +pcre

Please see http://www.swig.org for reporting bugs and further information
# system-wide python
/usr/bin/python3 --version
Python 3.8.5
# conda python: default environment

(base) adam:~$ which python
/opt/anaconda3/bin/python
(base) adam:~$ python --version
Python 3.8.3

The researcher is using python3.7, installed as an additional environment. opensim was working with 3.8, he just downgraded it because he uses 3.7 on his local machine.

Hacky fix I added into /etc/bash.bashrc:

# add opensim to system-wide pythonpath
export PYTHONPATH=/usr/local/lib/python3.8/site-packages/:$PYTHONPATH
export PATH=/opt/anaconda3/bin:$PATH

For the actual build, I built opensim with the scapulo joint merged. Can't remember why, could be because one of the researchers needs access to the joint for their models and I didn't want the hassle of setting up the library paths etc.:

commit 5cf9526e4f85bfbd2c1f3cac985727c37628ac77 (HEAD -> feature-merge-scapulothoracicjoint, adam/feature-merge-scapulothoracicjoint)
Author: Adam Kewley <[email protected]>
Date:   Thu Sep 3 10:23:55 2020 +0200

    Merge ScapulothoracicJoint plugin (from https://github.com/opensim-org/ScapulothoracicJointPlugin)

Build script (not my finest work: something I had lying around from months ago):

#!/usr/bin/env bash

# (before) checkout this project
# git clone https://github.com/opensim-org/opensim-core.git
# cd opensim-core/

# (before) install package-managed dependencies
#apt-get install git cmake cmake-curses-gui \
#                freeglut3-dev libxi-dev libxmu-dev \
#                liblapack-dev swig python-dev default-jdk

# CMAKE_BUILD_TYPE: what type of build to run
#   Debug           Unoptimized (10x slower) build with debug symbols
#   Release         Optimized without debug symbols
#   RelWithDebInfo  Optimized build with debug symbols (default)
#   MinSizeRel      Optimized **for size** build without debug symbols

opensim_project="${PWD}"

# where build intermediates are placed
opensim_build_dir="${opensim_project}/opensim-core-build"

# where built binaries are placed

# same, but for vendored dependencies
dependencies_project="${opensim_project}/dependencies"
dependencies_build_dir="${opensim_project}/opensim-core-dependencies-build"

# number of build targets to build in parallel
num_build_jobs=$(nproc)


# build vendored dependencies that OpenSim uses
mkdir -p "${dependencies_build_dir}"
pushd "${dependencies_build_dir}"
      cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
      "${dependencies_project}"
make -j"${num_build_jobs}"
popd

# build OpenSim
mkdir -p "${opensim_build_dir}"
pushd "${opensim_build_dir}"
cmake -DOPENSIM_DEPENDENCIES_DIR="${opensim_project}/opensim_dependencies_install" -DBUILD_JAVA_WRAPPING=OFF \
      -DCMAKE_BUILD_TYPE=RelWithDebInfo \
      "${opensim_project}"

make -j "${num_build_jobs}"
ctest -j "${num_build_jobs}"
make install
popd

@aymanhab
Copy link
Member

Development builds as of PR #2987 are made against python 3.7 and numpy 1.19

@jenhicks
Copy link
Member

@aymanhab What is the status of this issue?

@aymanhab
Copy link
Member

We used Anaconda for the Moco workshop at TGCS, using python 3.8 so I assume this is fixed already, but I haven't used the colab environment directly, maybe others did
e.g. @carmichaelong @nickbianco
I can try while testing 4.3

@carmichaelong
Copy link
Member

If this issue is strictly about OpenSim working with 3.8, then we should at least have this tested well with Windows and Mac environments. @aymanhab have you tried on Linux?

I haven't tried using OpenSim with colab yet.

@kidzik
Copy link

kidzik commented Aug 16, 2021

I was using it in a workshop, but I used a workaround hack -- participants had local binaries of OpenSim (not in google's cloud) and colab connected to these local binaries
https://colab.research.google.com/drive/1Kbubb9_L-MDtjt0nHVYR_zF9CK1Onz4C

@aymanhab
Copy link
Member

Successful run in browser with 3.8 and OpenSim 4.3 Beta as shown here
CaptureJupyterNBrowser

@clnsmith
Copy link
Contributor

Slow response... but this issue is solved my perspective.

I just went through the opensim python documentation page again to update to source code changes for conda and the documentation page was clear for me.

A trick for building from source where you want OpenSim to find a custom Anaconda environment:
On windows building with CMAKE GUI:
"Add Entry"
Python3_ROOT_DIR=C:/Users/USERNAME/anaconda3/envs/opensim_jam

where opensim_jam is the custom environment name.

@nickbianco
Copy link
Member

I've also needed to set Python3_ROOT_DIR when building OpenSim from source to set my desired conda environment. We should document this in the updated build instructions (related: #3178).

@ParticularMiner
Copy link

ParticularMiner commented Jun 13, 2022

I'd be grateful if someone could explain how os.add_dll_directory(...) works.

Python documentation seems to indicate that setting the PATH environment variable in Windows to "C:\OpenSim 4.3\bin" in order to enable the file-access of _simbody.lib is not required for Python versions 3.8+:

Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution. If your application relies on these mechanisms, you should check for add_dll_directory() and if it exists, use it to add your DLLs directory while loading your library.

The OpenSim documentation also says the same thing:

Starting at version 3.8, Python changed how dll's are located on windows, in particular PATH is not used any more, instead every environment should set the path to locate the dlls using ...

But this is not what I observe in practice: it is still necessary to set the PATH environment variable!

I might be missing something. But at the moment, I suspect this might be causing confusion to OpenSim end-users.

@aymanhab
Copy link
Member

aymanhab commented Jun 13, 2022 via email

@ParticularMiner
Copy link

ParticularMiner commented Jun 13, 2022

Thank you very much @aymanhab for the pointers! I'm also excited to learn about the new conda release. That would certainly make things much easier.

So I executed the following commands without any problems:

> conda create -n gaitdev
> conda install -c opensim-org -n gaitdev opensim
> conda activate gaitdev
(gaitdev) > python
Python 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:32:50) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

But got the following error on attempting to import opensim:

>>> import opensim as osim
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\runner\anaconda3\envs\gaitdev\lib\opensim\__init__.py", line 7, in <module>
    os.add_dll_directory(DLL_PATH)
NameError: name 'DLL_PATH' is not defined
>>> 

Is this expected behavior? I had expected the conda installation script to set the dll paths automatically so that I wouldn't have to do it myself (by running python setup_win_python38.py in C:\Users\runner\anaconda3\envs\gaitdev\Lib , for example).

@ParticularMiner
Copy link

ParticularMiner commented Jun 14, 2022

@aymanhab

FYI, following my previous message, I modified the following line in my conda environment's C:\Users\runner\anaconda3\envs\gaitdev\Lib\__init__.py:

if (os.path.exists(os.path.join(sys.prefix, 'conda'))):

to

   if (os.path.exists(os.path.join(sys.prefix, 'Lib'))):

This cleared the runtime error above, but raised another error (the old one):

> python -c "import opensim"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\runner\anaconda3\envs\gaitdev\Lib\opensim\__init__.py", line 10, in <module>
    from .simbody import *
  File "C:\Users\runner\anaconda3\envs\gaitdev\Lib\opensim\simbody.py", line 13, in <module>
    from . import _simbody
ImportError: DLL load failed while importing _simbody: The specified module could not be found.

I also tried setting environment variable CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1 as suggested in conda/conda#10897 (comment) and even manually set the PATH environment variable.

None of the above attempts worked.

Question: Do I need to install the full OpenSim 4.4 (non-python) application somewhere on my system, in addition to the conda package opensim installation?

@aymanhab
Copy link
Member

You don't need to install OpenSim elsewhere, this is supposed to be self contained.
That said, you have to use specific python versions (we have python 3.7,8,9 but no 3.10). Also the line you modified was supposed to detect if the python in use is conda based but other installation/settings could fail, I'm curious why the line failed and you needed to modify it (so we can make this detection more robust).

@ParticularMiner
Copy link

ParticularMiner commented Jun 14, 2022

you have to use specific python versions (we have python 3.7,8,9 but no 3.10)

Thanks for the info, @aymanhab. However, removing and recreating the environment with conda create -n gaitdev python=3.9 for instance, did not solve the problem.

I'm curious why the line failed

It seems that the conda-detection line failed on my system because my conda installation does not have a subdirectory named "conda". I guess this is the default configuration for conda environments. But correct me if I'm wrong.

@aymanhab
Copy link
Member

Some suggestions:

  1. I'd make sure no other opensim installation is in the path or leftovers in your anaconda environment, etc.
  2. Try installation in base environment and make sure you get the expected python version (if that's not supported yet let me know and I'll make one). You're unlikely to have multiple versions around at the same time anyway.
  3. If you try installation and dll fails to load, use dependency walker to find out what dlls/libraries are missing.
    Let us know how that goes to document your findings. Thank you

@ParticularMiner
Copy link

Installation in the base environment yielded the same results as above:

(base) > python --version
Python 3.8.8
(base) > conda install -c opensim-org opensim
(base) > python -c "import opensim"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\runner\anaconda3\lib\opensim\__init__.py", line 7, in <module>
    os.add_dll_directory(DLL_PATH)
NameError: name 'DLL_PATH' is not defined

This is my first time using dependency walker. Could you direct me on how to use it in this case, please. My efforts to pass python -c "import opensim" to dependency walker did not produce any output:

(base) > C:\depends.exe python -c "import opensim"

@aymanhab
Copy link
Member

Modify DLL_PATH to the folder that contains all the opensim dlls first

@aymanhab
Copy link
Member

Or you could change the line to
os.path.exists(os.path.join(sys.prefix, 'conda-meta'))
and see if it detects conda correctly

@ParticularMiner
Copy link

@aymanhab

Thanks for your help!

Or you could change the line to
os.path.exists(os.path.join(sys.prefix, 'conda-meta'))
and see if it detects conda correctly

Yes! That worked for the base environment. 🎉 But not for other environments.

I see you've already pushed the 'conda-meta' correction to the conda repository. However, I'm now getting the following errors when installing opensim:

(base) > conda install -c opensim-org opensim
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\runner\anaconda3

  added / updated specs:
    - opensim


The following NEW packages will be INSTALLED:

  freeglut           conda-forge/win-64::freeglut-3.2.2-h0e60522_1
  intel-openmp       conda-forge/win-64::intel-openmp-2022.1.0-h57928b3_3787
  libblas            conda-forge/win-64::libblas-3.9.0-15_win64_mkl
  libcblas           conda-forge/win-64::libcblas-3.9.0-15_win64_mkl
  liblapack          conda-forge/win-64::liblapack-3.9.0-15_win64_mkl
  mkl                conda-forge/win-64::mkl-2022.1.0-h6a75c08_874
  numpy              conda-forge/win-64::numpy-1.22.4-py38h1d2777f_0
  opensim            opensim-org/win-64::opensim-4.4-py38np120
  tbb                conda-forge/win-64::tbb-2021.5.0-h2d74725_1


Proceed ([y]/n)?

Preparing transaction: done
Verifying transaction: /
SafetyError: The package for opensim located at C:\Users\runner\anaconda3\pkgs\opensim-4.4-py38np120
appears to be corrupted. The path 'Lib/opensim/__init__.py'
has an incorrect size.
  reported size: 568 bytes
  actual size: 573 bytes

ClobberError: This transaction has incompatible packages due to a shared path.
  packages: conda-forge/win-64::libblas-3.9.0-15_win64_mkl, opensim-org/win-64::opensim-4.4-py38np120
  path: 'library/bin/libblas.dll'


ClobberError: This transaction has incompatible packages due to a shared path.
  packages: conda-forge/win-64::liblapack-3.9.0-15_win64_mkl, opensim-org/win-64::opensim-4.4-py38np120
  path: 'library/bin/liblapack.dll'



done
Executing transaction: done

(base) >

@aymanhab
Copy link
Member

aymanhab commented Jun 14, 2022

Can you clarify:

  1. If your base environment is working out of the box, I haven't pushed anything new to the conda package.
  2. Conflict with other potential pkgs is a big issue that has no simple solution, can you uninstall the other libblas? why did conda decide to download a different libblas is beyond me

@aymanhab
Copy link
Member

For dependencies, I get Dependencies from here https://github.com/lucasg/Dependencies and drag dlls or pyds into it to see if anything is missing from the packaging but that doesn't appear to be the case

@ParticularMiner
Copy link

ParticularMiner commented Jun 14, 2022

In my base environment,

  • opensim is being imported without problems despite the installation error messages.
  • However, running python exampleSlidingMass.py yields the following errors:
    Traceback (most recent call last):
      File "exampleSlidingMass.py", line 87, in <module>
        solution = study.solve()
      File "C:\Users\runner\anaconda3\lib\opensim\moco.py", line 8397, in solve
        return _moco.MocoStudy_solve(self)
    RuntimeError: std::exception in 'OpenSim::MocoSolution OpenSim::MocoStudy::solve() const': MocoCasADiSolver is not available.
            Thrown at MocoCasADiSolver.cpp:448 in solveImpl().
    

In the other environments, import opensim does not work.

Unfortunately I have other packages that depend on that libblas, so I hesitate to remove it. But I'll see what I can do about this.

Strange that you haven't pushed anything to the conda repository. I'm seeing that __init__.py already has the 'conda-meta' correction directly upon conda installation of opensim (that is, I do not need to change the line myself).

@aymanhab
Copy link
Member

For the Moco side, the default package doesn't include Moco, we'll provide this soon, so no surprise (the anaconda website shows two packages opensim, opensim-moco though the latter is rather old).
We can build with other libblas if needed, particularly to avoid collision with commonly used packages. Is that related to using numpy120?

@ParticularMiner
Copy link

Is that related to using numpy120?

I guess so. I'm not sure about the exact version though.

@aymanhab
Copy link
Member

Can you do conda list and send output?

@ParticularMiner
Copy link

Sure.

Click to see conda list output
> conda list
# packages in environment at C:\Users\runner\anaconda3:
#
# Name                    Version                   Build  Channel
anaconda-client           1.8.0              pyhd8ed1ab_0    conda-forge
anaconda-navigator        2.2.0            py38haa95532_0
attrs                     21.4.0             pyhd8ed1ab_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
backports.tempfile        1.0                        py_0    conda-forge
backports.weakref         1.0.post1       pyhd8ed1ab_1003    conda-forge
beautifulsoup4            4.11.1             pyha770c72_0    conda-forge
brotlipy                  0.7.0           py38h294d835_1004    conda-forge
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2022.5.18.1          h5b45459_0    conda-forge
certifi                   2022.5.18.1      py38haa244fe_0    conda-forge
cffi                      1.15.0           py38hd8c33c5_0    conda-forge
chardet                   4.0.0            py38haa244fe_3    conda-forge
charset-normalizer        2.0.12             pyhd8ed1ab_0    conda-forge
clangdev                  5.0.0                   flang_3  [flang]  conda-forge
click                     8.1.3            py38haa244fe_0    conda-forge
clyent                    1.2.2                      py_1    conda-forge
cmake                     3.21.3               h39d44d4_0    conda-forge
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
conda                     4.13.0           py38haa244fe_1    conda-forge
conda-build               3.21.9           py38haa244fe_0    conda-forge
conda-content-trust       0.1.3              pyhd8ed1ab_0    conda-forge
conda-env                 2.6.0                         1
conda-package-handling    1.8.1            py38h31c79cd_1    conda-forge
conda-repo-cli            1.0.4              pyhd3eb1b0_0
conda-token               0.3.0              pyhd3eb1b0_0
conda-verify              3.4.2                      py_1
console_shortcut          0.1.1                         4
cryptography              37.0.2           py38hb7941b4_0    conda-forge
filelock                  3.7.1              pyhd8ed1ab_0    conda-forge
flang                     5.0.0           he025d50_20180525    conda-forge
freeglut                  3.2.2                h0e60522_1    conda-forge
freetype                  2.10.4               h546665d_1    conda-forge
future                    0.18.2           py38haa244fe_5    conda-forge
gettext                   0.19.8.1          ha2e2712_1008    conda-forge
glob2                     0.7                        py_0    conda-forge
gst-plugins-base          1.20.2               he07aa86_1    conda-forge
gstreamer                 1.20.2               hdff456e_1    conda-forge
icu                       70.1                 h0e60522_0    conda-forge
idna                      3.3                pyhd8ed1ab_0    conda-forge
importlib-metadata        4.11.4           py38haa244fe_0    conda-forge
importlib_resources       5.7.1              pyhd8ed1ab_1    conda-forge
intel-openmp              2022.1.0          h57928b3_3787    conda-forge
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
jpeg                      9e                   h8ffe710_1    conda-forge
jsonschema                4.6.0              pyhd8ed1ab_0    conda-forge
jupyter_core              4.10.0           py38haa244fe_0    conda-forge
krb5                      1.19.3               h1176d77_0    conda-forge
lcms2                     2.12                 h2a16943_0    conda-forge
lerc                      3.0                  h0e60522_0    conda-forge
libarchive                3.5.2                hb45042f_2    conda-forge
libblas                   3.9.0              15_win64_mkl    conda-forge
libcblas                  3.9.0              15_win64_mkl    conda-forge
libclang                  14.0.5          default_h77d9078_0    conda-forge
libclang13                14.0.5          default_h77d9078_0    conda-forge
libdeflate                1.10                 h8ffe710_0    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libflang                  5.0.0           h6538335_20180525    conda-forge
libglib                   2.70.2               h3be07f2_4    conda-forge
libiconv                  1.16                 he774522_0    conda-forge
liblapack                 3.9.0              15_win64_mkl    conda-forge
liblief                   0.11.5               h0e60522_1    conda-forge
libogg                    1.3.4                h8ffe710_1    conda-forge
libpng                    1.6.37               h1d00b33_2    conda-forge
libtiff                   4.3.0                hc4061b1_4    conda-forge
libvorbis                 1.3.7                h0e60522_0    conda-forge
libwebp                   1.2.2                h57928b3_0    conda-forge
libwebp-base              1.2.2                h8ffe710_1    conda-forge
libxcb                    1.13              hcd874cb_1004    conda-forge
libxml2                   2.9.14               hf5bbc77_0    conda-forge
libzlib                   1.2.12               h8ffe710_0    conda-forge
llvm-meta                 5.0.0                         0    conda-forge
lz4-c                     1.9.3                h8ffe710_1    conda-forge
lzo                       2.10              he774522_1000    conda-forge
m2-msys2-runtime          2.5.0.17080.65c939c               3    conda-forge
m2-patch                  2.7.5                         2    conda-forge
m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
m2w64-gcc-libs            5.3.0                         7    conda-forge
m2w64-gcc-libs-core       5.3.0                         7    conda-forge
m2w64-gmp                 6.1.0                         2    conda-forge
m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
markupsafe                2.1.1            py38h294d835_1    conda-forge
menuinst                  1.4.16           py38he774522_1
mkl                       2022.1.0           h6a75c08_874    conda-forge
msys2-conda-epoch         20160418                      1    conda-forge
navigator-updater         0.2.1                    py38_0
nbformat                  5.4.0              pyhd8ed1ab_0    conda-forge
ninja                     1.10.2               h2d74725_1    conda-forge
numpy                     1.22.4           py38h1d2777f_0    conda-forge
openjpeg                  2.4.0                hb211442_1    conda-forge
openmp                    5.0.0                    vc14_1    conda-forge
opensim                   4.4                   py38np120    opensim-org
openssl                   1.1.1o               h8ffe710_0    conda-forge
packaging                 21.3               pyhd8ed1ab_0    conda-forge
pcre                      8.45                 h0e60522_0    conda-forge
perl                      5.32.1.1        0_h57928b3_strawberry    conda-forge
pillow                    9.1.1            py38hd8e0db4_0    conda-forge
pip                       22.1.2             pyhd8ed1ab_0    conda-forge
pkginfo                   1.8.3              pyhd8ed1ab_0    conda-forge
powershell_shortcut       0.0.1                         3
psutil                    5.9.1            py38h294d835_0    conda-forge
pthread-stubs             0.4               hcd874cb_1001    conda-forge
py-lief                   0.11.5           py38h885f38d_1    conda-forge
pycosat                   0.6.3           py38h294d835_1010    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pyjwt                     2.4.0              pyhd8ed1ab_0    conda-forge
pyopenssl                 22.0.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyqt                      5.15.4           py38h75e37d8_1    conda-forge
pyqt5-sip                 12.9.0           py38h885f38d_1    conda-forge
pyrsistent                0.18.1           py38h294d835_1    conda-forge
pysocks                   1.7.1            py38haa244fe_5    conda-forge
python                    3.8.8                hdbf39b2_5
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-fastjsonschema     2.15.3             pyhd8ed1ab_0    conda-forge
python-libarchive-c       4.0              py38haa244fe_1    conda-forge
python_abi                3.8                      2_cp38    conda-forge
pytz                      2022.1             pyhd8ed1ab_0    conda-forge
pywin32                   303              py38h294d835_0    conda-forge
pyyaml                    6.0              py38h294d835_4    conda-forge
qt-main                   5.15.4               h467ea89_2    conda-forge
qtpy                      2.1.0              pyhd8ed1ab_0    conda-forge
requests                  2.28.0             pyhd8ed1ab_0    conda-forge
ripgrep                   13.0.0               h7f3b576_2    conda-forge
ruamel_yaml               0.15.80         py38h294d835_1007    conda-forge
setuptools                62.3.4           py38haa244fe_0    conda-forge
sip                       6.5.1            py38h885f38d_2    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
soupsieve                 2.3.1              pyhd8ed1ab_0    conda-forge
sqlite                    3.38.5               h8ffe710_0    conda-forge
tbb                       2021.5.0             h2d74725_1    conda-forge
tk                        8.6.12               h8ffe710_0    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tqdm                      4.64.0             pyhd8ed1ab_0    conda-forge
traitlets                 5.2.2.post1        pyhd8ed1ab_0    conda-forge
ucrt                      10.0.20348.0         h57928b3_0    conda-forge
ujson                     5.3.0            py38h885f38d_0    conda-forge
urllib3                   1.26.9             pyhd8ed1ab_0    conda-forge
vc                        14.2                 hb210afc_6    conda-forge
vs2015_runtime            14.29.30037          h902a5da_6    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
win_inet_pton             1.1.0            py38haa244fe_4    conda-forge
xorg-libxau               1.0.9                hcd874cb_0    conda-forge
xorg-libxdmcp             1.1.3                hcd874cb_0    conda-forge
xz                        5.2.5                h62dcd97_1    conda-forge
yaml                      0.2.5                h8ffe710_2    conda-forge
zipp                      3.8.0              pyhd8ed1ab_0    conda-forge
zlib                      1.2.12               h8ffe710_0    conda-forge
zstd                      1.5.2                h6255e5f_1    conda-forge

@aymanhab
Copy link
Member

I see you have numpy 1.22.4 while our build uses numpy 1.20 exclusively, this could be the problem. You can use "conda search package_name --info" to see the dependencies of suspected culprits.

@ParticularMiner
Copy link

@aymanhab

I'm not sure what happened, but import opensim now works on the other environments too. Also, the __init__.py file was installed by conda automatically with the conda-meta correction already made.

@aymanhab
Copy link
Member

Wow, that's wonderful. If using 'conda-meta' works consistently I can update the code as well on our side to make sure other users get it as well.

@ParticularMiner
Copy link

Thanks again for your help @aymanhab !

@tkuchida
Copy link
Member

tkuchida commented Jul 8, 2022

@aymanhab The beta has 'conda' not 'conda-meta'. Didn't work for me with 'conda', seems to work with 'conda-meta'. Perhaps this change can be included in the release or at least documented somewhere more visible to save users time in the future ⏰

@conradotl
Copy link

To update the scenario:

I just had the "importError: DLL load failed while importing _simbody:" problem trying to use a python 3.9 conda env, but it is working fine in 3.8 after mannualy inserting DLL path to system path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests