Linux(Ubuntu)安装Mujoco、mujoco-py的详细步骤、安装教程
参考链接:https://blog.csdn.net/Youtian_/article/details/103841453,【Linux】Ubun16.04服务器配置Mujoco的各种错误解决方案
下载链接:Releases · deepmind/mujoco (github.com)
mujoco-py
![Build Status]()
MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py
allows using MuJoCo from Python 3.
This library has been updated to be compatible with MuJoCo version 2.1 released on 2021-10-18.
Synopsis
Requirements
The following platforms are currently supported:
- Linux with Python 3.6+. See the
Dockerfile
for the canonical list of system dependencies. - OS X with Python 3.6+.
The following platforms are DEPRECATED and unsupported:
- Windows support has been DEPRECATED and removed in 2.0.2.0. One known good past version is 1.50.1.68.
- Python 2 has been DEPRECATED and removed in 1.50.1.0. Python 2 users can stay on the
0.5
branch. The latest release there is0.5.7
which can be installed withpip install mujoco-py==0.5.7
.
Install MuJoCo
- Download the MuJoCo version 2.1 binaries for Linux or OSX.
- Extract the downloaded
mujoco210
directory into~/.mujoco/mujoco210
.
mkdir ~/.mujoco cp mujoco210-linux-x86_64.tar.gz ~/.mujoco cd ~/.mujoco tar -xzvf mujoco210-linux-x86_64.tar.gz
If you want to specify a nonstandard location for the package, use the env variable MUJOCO_PY_MUJOCO_PATH
.
Finally, add path to your environment variable.
- Please add following line to .bashrc: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mujoco210/bin (输入MuJoCo对应的路径)
PS:有时候绝对路径比~更加不容易出错
Install and use mujoco-py
To include mujoco-py
in your own package, add it to your requirements like so:
mujoco-py<2.2,>=2.1
To play with mujoco-py
interactively, follow these steps:
$ pip3 install -U 'mujoco-py<2.2,>=2.1'
$ python3
import mujoco_py
import os
mj_path = mujoco_py.utils.discover_mujoco()
xml_path = os.path.join(mj_path, 'model', 'humanoid.xml')
model = mujoco_py.load_model_from_path(xml_path)
sim = mujoco_py.MjSim(model)
print(sim.data.qpos)
# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
sim.step()
print(sim.data.qpos)
# [-2.09531783e-19 2.72130735e-05 6.14480786e-22 -3.45474715e-06
# 7.42993721e-06 -1.40711141e-04 -3.04253586e-04 -2.07559344e-04
# 8.50646247e-05 -3.45474715e-06 7.42993721e-06 -1.40711141e-04
# -3.04253586e-04 -2.07559344e-04 -8.50646247e-05 1.11317030e-04
# -7.03465386e-05 -2.22862221e-05 -1.11317030e-04 7.03465386e-05
# -2.22862221e-05]
Ubuntu installtion troubleshooting
Because mujoco_py
has compiled native code that needs to be linked to a supplied MuJoCo binary, it's installation on linux can be more challenging than pure Python source packages.
To install mujoco-py on Ubuntu, make sure you have the following libraries installed:
sudo apt install libosmesa6-dev libgl1-mesa-glx libglfw3 or # 上面三个库的依赖不存在,或者已经存在版本更高的依赖而导致安装无法继续
sudo aptitude install libosmesa6-dev libgl1-mesa-glx libglfw3
If you installed above libraries and you still see an error that -lGL
cannot be found, most likely you need to create the symbolic link directly:
sudo aptitude install libgl1-mesa-dev sudo ln -s /usr/lib/x86_64-linux-gnu/libGL.so.1 /usr/lib/x86_64-linux-gnu/libGL.so