使用mujoco-py包的MuJoCo物理库的Python绑定

时间:2016-08-04 11:36:35

标签: python c++ dll physics dllimport

我想使用MuJoCo(http://www.mujoco.org/),一个带有python绑定的高级物理模拟器(https://github.com/openai/mujoco-py)。

我已获得我的MuJoCo许可证文件mjkey.text,并相应地将所需的路径MUJOCO_PY_MJKEY_PATH,MUJOCO_PY_MJPRO_PATH添加到环境变量中。

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

然而,我想用以下简单代码导入libray,

import mujoco_py

我收到以下错误消息。

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

我在Windows 7 64位上使用64位的Python 3.5.1,MuJoCo 1.31 64位。

我猜这个问题是由于某种不兼容性造成的,我还试用了32.5位的32.5位的Python 3.5.2和32位的MuJoCo。甚至,我尝试了非逻辑32位Python和64位MuJoCo组合,反之亦然。

已编译的给定示例&#34; simulate.exe&#34;在MuJoCo图书馆工作得很好。所以,我想我的64位MuJoCo库没有问题。 (顺便说一句,它的32位版本不能在64位Windows上运行)

因此,在将C ++库加载到Python时可能会出现问题。我调试并至少检查mujoco_py库中的Python代码是否尝试加载&#34; mujoco131.lib&#34; (不是&#34; mujoco131.dll&#34;尽管)来自正确的路径。然后发生错误,代码无法继续运行。

我愿意接受任何意见和建议。

干杯!祝你有愉快的一天!

1 个答案:

答案 0 :(得分:6)

尝试修改mjlib.py,将"bin/mujoco131.lib"替换为加载程序中的"bin/mujoco131.dll"

我还必须在platname = "win"

中明确指定platname_targdir.py