Problem about importing opensim in Pycharm

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Zuren Arrh
Posts: 6
Joined: Tue Sep 18, 2018 6:07 am

Problem about importing opensim in Pycharm

Post by Zuren Arrh » Sun Oct 14, 2018 7:15 am

Hi all,
Rencently I'm trying to learn to use OpenSim through Python, and choose the NIPS2018 competition 'AI for Prosthetics' to start. I follow the official instructions to install some packages as follow:

Code: Select all

conda create -n opensim-rl -c kidzik opensim python=3.6.1
source activate opensim-rl
conda install -c conda-forge lapack git
pip install git+https://github.com/stanfordnmbl/osim-rl.git
Up to now, everything works fine, and I can successfully 'import osim;import opensim' and run some easy code in the Anaconda Prompt and Spyder. The strange thing is when I try to create a project in Pycharm and do the same thing as in the Anaconda Prompt and Spyser, some errors arise.

When I import osim, every thing works fine as in Anaconda Prompt and Spyder:

Code: Select all

>>> import osim
>>> 
However, when I import osim.env, something strange happened:

Code: Select all

>>> import osim.env
Traceback (most recent call last):
  File "E:\Anaconda3\envs\opensim-rl\lib\site-packages\opensim\simbody.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "E:\Anaconda3\envs\opensim-rl\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 560, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: DLL load failed: the specific module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\Anaconda3\envs\opensim-rl\lib\site-packages\osim\env\__init__.py", line 3, in <module>
    from .osim import *
  File "E:\Anaconda3\envs\opensim-rl\lib\site-packages\osim\env\osim.py", line 6, in <module>
    import opensim
  File "E:\Anaconda3\envs\opensim-rl\lib\site-packages\opensim\__init__.py", line 1, in <module>
    from .simbody import *
  File "E:\Anaconda3\envs\opensim-rl\lib\site-packages\opensim\simbody.py", line 17, in <module>
    _simbody = swig_import_helper()
  File "E:\Anaconda3\envs\opensim-rl\lib\site-packages\opensim\simbody.py", line 16, in swig_import_helper
    return importlib.import_module('_simbody')
  File "E:\Anaconda3\envs\opensim-rl\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_simbody'
Now I try to import opensim, and the same error happened again:

Code: Select all

>>> import opensim
Traceback (most recent call last):
  File "E:\Anaconda3\envs\opensim-rl\lib\site-packages\opensim\simbody.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "E:\Anaconda3\envs\opensim-rl\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 560, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: DLL load failed: the specific module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\Anaconda3\envs\opensim-rl\lib\site-packages\opensim\__init__.py", line 1, in <module>
    from .simbody import *
  File "E:\Anaconda3\envs\opensim-rl\lib\site-packages\opensim\simbody.py", line 17, in <module>
    _simbody = swig_import_helper()
  File "E:\Anaconda3\envs\opensim-rl\lib\site-packages\opensim\simbody.py", line 16, in swig_import_helper
    return importlib.import_module('_simbody')
  File "E:\Anaconda3\envs\opensim-rl\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_simbody'
I just cannot understand why everything runs fine in Anaconda Prompt or Spyder, but not in Pycharm(I have checked the Project Interpreter in Pycharm, so I think the problem is not there).

Thanks,
Zurenarrh

Tags:

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

Re: Problem about importing opensim in Pycharm

Post by Dimitar Stanev » Mon Oct 15, 2018 12:28 am

Hi,

I think I have encountered a similar error. The problem may be due to installing these dependencies using administrative rights. A quick fix that may work for you is to try to add the folder which contains the DLLs (e.g. somewhere in E:\Anaconda3\envs\opensim-rl\lib\site-packages\opensim) to the python path variable before calling the import functions. You can check whether the aforementioned dlls are also located in these folders.

This is not a good solutions and I suggest that you install the dependencies without administrative rights.

Hope this helps.

User avatar
Zuren Arrh
Posts: 6
Joined: Tue Sep 18, 2018 6:07 am

Re: Problem about importing opensim in Pycharm

Post by Zuren Arrh » Tue Oct 16, 2018 3:35 am

mitkof6 wrote:
Mon Oct 15, 2018 12:28 am
Hi,

I think I have encountered a similar error. The problem may be due to installing these dependencies using administrative rights. A quick fix that may work for you is to try to add the folder which contains the DLLs (e.g. somewhere in E:\Anaconda3\envs\opensim-rl\lib\site-packages\opensim) to the python path variable before calling the import functions. You can check whether the aforementioned dlls are also located in these folders.

This is not a good solutions and I suggest that you install the dependencies without administrative rights.

Hope this helps.
I tried your method, and it worked! This problem bothered me for a long time, thanks a lot!
Hope this helps others with the same problem.

Thanks,
Zurenarrh

POST REPLY