mujoco可以认为是一个渲染引擎
mujoco_py保证可以通过python来和mujoco交互
因此本篇介绍如何安装mujoco及mujoco_py。
主要参考官方网站:openai/mujoco-py: MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3. (github.com)
1. Download the MuJoCo version 2.1 binaries for Linux or OSX, and extract the downloaded mujoco210
directory into ~/.mujoco/mujoco210
.
mkdir ~/.mujoco
cd ~/.mujoco
wget https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz
tar -zxvf mujoco210-linux-x86_64.tar.gz
2. Add the following to ~/.bashrc, and source ~/.bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/maohangyu/.mujoco/mujoco210/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia
3. Testing
cd ~/.mujoco/mujoco200/bin
./simulate ../model/humanoid.xml
出现下图所示的画面,表示mujoco安装成功;当然显卡驱动版本太低的话,只会出现一个黑框,没有图像(但是也可以认为安装成功了)。
1. 安装mujoco_py对应版本
pip3 install -U 'mujoco-py<2.2,>=2.1'
2. 测试是否安装成功
$ 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]
3. 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.
3.1 GCC问题:distutils.errors.CompileError: command '/usr/bin/gcc' failed with exit code 1
执行下面命令:
sudo apt install libosmesa6-dev libgl1-mesa-glx libglfw3
sudo apt-get install patchelf
sudo apt-get install libglew-dev glew-utils
如果执行上述命令有问题,参考:
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
(194条消息) 【已解决】Could not get lock /var/lib/dpkg/lock-frontend_Bungehurst的博客-CSDN博客
其它参考文章:
安装Mujoco、Mujoco_py、D4RL、gym、d3rlpy以及Pycharm远程连接服务器问题 - 知乎 (zhihu.com)
(194条消息) Ubuntu20.04安装mujoco210、mujoco_py_Nehemiah_Li的博客-CSDN博客