1、安装步骤
下载mujoco,下载链接如下:
Release 2.1.0 · google-deepmind/mujoco · GitHub
解压并安装
tar -zxvf mujoco210-linux-x86_64.tar.gz -C ~/.mujoco
下载mjkey.txt,下载链接如下,并将其拷贝至.mujoco\mujoco200\bin文件夹内
https://www.roboti.us/license.html
配置环境变量,sudo gedit ~/.bashrc,打开后在最后面插入如下指令:
export MUJOCO_KEY_PATH=~/.mujoco${MUJOCO_KEY_PATH}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/gh/.mujoco/mujoco210/bin
保存关闭.bashrc,并在终端输入:source ~/.bashrc
2、测试mujoco
cd ~/.mujoco/mujoco210/bin
./simulate ../model/humanoid.xml
会出现:
说明安装成功
3、安装mujoco-py
新建conda环境
conda create --name mujoco1 python=3.8
conda activate mujoco1
安装:
git clone https://github.com/openai/mujoco-py.git
cd mujoco-py
pip install -r requirements.txt
pip install -r requirements.dev.txt
pip3 install -U 'mujoco-py<2.2,>=2.1'
配置环境:
sudo gedit ~/.bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia
source ~/.bashrc
4、python代码测试
新建test1.py文件:
import os
# os.add_dll_directory("home/qys/.mujoco/mujoco210/bin")
import mujoco_py
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)
如果成功会出现:
[0. 0. 1.4 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[-1.12164337e-05 7.29847036e-22 1.39975300e+00 9.99999999e-01
1.80085466e-21 4.45933954e-05 -2.70143345e-20 1.30126513e-19
-4.63561234e-05 -1.88020744e-20 -2.24492958e-06 4.79357124e-05
-6.38208396e-04 -1.61130312e-03 -1.37554006e-03 5.54173825e-05
-2.24492958e-06 4.79357124e-05 -6.38208396e-04 -1.61130312e-03
-1.37554006e-03 -5.54173825e-05 -5.73572648e-05 7.63833991e-05
-2.12765194e-05 5.73572648e-05 -7.63833991e-05 -2.12765194e-05]
5、问题解决
01、出现:
Error compiling Cython file:
------------------------------------------------------------
...
See c_warning_callback, which is the C wrapper to the user defined function
'''
global py_warning_callback
global mju_user_warning
py_warning_callback = warn
mju_user_warning = c_warning_callback
^
输入:
pip uninstall cython
pip install cython==0.29.21
02、出现:
fatal error: X11/Xlib.h: No such file or directory
输入:
sudo apt -get install libx11-dev
03、出现:
fatal error: GL/glew.h: No such file or directory
输入:
sudo apt-get install -y libglew-dev
04、出现:
FileNotFoundError: [Errno 2] No such file or directory: 'patchelf'
输入:
sudo apt-get install patchelf
至此已经解决所遇到的所有问题。
再次运行test1.py就可以出现4中的结果。
参考博客:
[记录]安装mujoco_py并测试时提示Cython.Compiler.Errors.CompileError_mojoco.py报错compile error-CSDN博客