Python binding for MuJoCo physics library using mujoco-py package
Asked Answered
I

1

8

I want to use MuJoCo (http://www.mujoco.org/), an advanced physics simulator with python bindings (https://github.com/openai/mujoco-py).

I've got my MuJoCo license file mjkey.text and added the required paths MUJOCO_PY_MJKEY_PATH, MUJOCO_PY_MJPRO_PATH to the environment variables accordingly.

MUJOCO_PY_MJPRO_PATH = C:\Dropbox\PhD\MuJoCo\mjpro131
MUJOCO_PY_MJKEY_PATH = C:\Dropbox\PhD\MuJoCo\mjpro131\bin

However, a soon as I want to import the libray with the following simple code,

import mujoco_py

I got the following error message.

C:\Dropbox\Python\Anaconda\python.exe
C:/Dropbox/PhD/Python/X/MujocoHelloWorld/test.py
Traceback (most recent call last):
  File "C:/Dropbox/PhD/Python/X/MujocoHelloWorld/test.py", line 1, in <module>
    import mujoco_py
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "C:\Dropbox\Python\Anaconda\lib\site-packages\mujoco_py-0.5.4-py3.5.egg\mujoco_py\__init__.py", line 4, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "C:\Dropbox\Python\Anaconda\lib\site-packages\mujoco_py-0.5.4-py3.5.egg\mujoco_py\mjviewer.py", line 7, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "C:\Dropbox\Python\Anaconda\lib\site-packages\mujoco_py-0.5.4-py3.5.egg\mujoco_py\mjcore.py", line 6, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "C:\Dropbox\Python\Anaconda\lib\site-packages\mujoco_py-0.5.4-py3.5.egg\mujoco_py\mjlib.py", line 21, in <module>
  File "C:\Dropbox\Python\Anaconda\lib\ctypes\__init__.py", line 425, in LoadLibrary
    return self._dlltype(name)
  File "C:\Dropbox\Python\Anaconda\lib\ctypes\__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

Process finished with exit code 1

I am using a Python 3.5.1 64-bit on a Windows 7 64-bit with MuJoCo 1.31 64-bit.

I guessed the problem is due to a some kind of incompatibility, I also tried Python 3.5.2 32-bit with MuJoCo 1.31 32-bit. Even, I tried the non-logical 32-bit Python and 64-bit MuJoCo combination and vice versa.

The already compiled given example "simulate.exe" in the MuJoCo library works perfectly. So, I guess there is no problem with the 64-bit MuJoCo library that I have. ( By the way, 32-bit version of it doesn't run on 64-bit Windows )

So, the problem should probably occur when loading the C++ library to Python. I debugged and at least checked that the Python code in mujoco_py library tries to load "mujoco131.lib" ( Not "mujoco131.dll" though ) from the correct path. And then the error occurs and code fails to run further.

I am open to any kind of comments and suggestions..

Cheers! And have a nice day!

Incommodious answered 4/8, 2016 at 11:36 Comment(0)
S
8

Try editing mjlib.py, replacing "bin/mujoco131.lib" with "bin/mujoco131.dll" in the loader.

I also had to explicitly specify platname = "win" in platname_targdir.py

Sinuous answered 8/8, 2016 at 23:1 Comment(4)
The changes actually helped to avoid the error(s). Thanks a lot. But now the import simply hangs without any error. print("hey") import mujoco_py print("hey") This code prints the first "hey" and then keeps on running forever.. Any further ideas?Merrymaker
You might want to try downgrading to python 3.4 via conda install python=3.4 conda install mingw libpython numpySinuous
Thanks for the suggestion but still not working. I guess it is a configuration problem though.. If it is working for you, can you write down the versions of the depending libraries.. Or more ideas? :DMerrymaker
I changed result = mjlib.mj_activate(file_path) to result = mjlib.mj_activate(file_path + '\\mjkey.txt') in register_license() function in mjcore.py. I seems like it is working. Thanks for all the help..Merrymaker

© 2022 - 2024 — McMap. All rights reserved.