一.安装mujoco
1.官网下载mujoco210文件
https://github.com/deepmind/mujoco/releases/tag/2.1.0
2.将下载的文件解压到指定目录~/.mujoco下
mkdir ~/.mujoco
tar -zxvf mujoco210-linux-x86_64.tar.gz -C ~/.mujoco
3.配置.bashrc环境文件,在文档最后一行加入下面代码然后保存退出文档
gedit ~/.bashrc
export LD_LIBRARY_PATH=~/.mujoco/mujoco210/bin
source ~/.bashrc
4.测试
cd ~/.mujoco/mujoco210/bin
./simulate ../model/humanoid.xml
二、安装mujoco_py
1.git下载
git clone https://github.com/openai/mujoco-py.git
2.conda环境配置
conda create -n mujo python=3.8
conda activate mujo
cd ~/mujoco-py
pip3 install -U 'mujoco-py<2.2,>=2.1'
pip3 install -r requirements.txt
pip3 install -r requirements.dev.txt
python3 setup.py install
3.配置bash环境
gedit ~/.bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia
source ~/.bashrc
4.测试
测试代码
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]
三、出现的问题
1.Compiling /home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx
performance hint: anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx:67:5: Exception check on ‘c_warning_callback’ will always require the GIL to be acquired.
Possible solutions:
1. Declare the function as ‘noexcept’ if you control the definition and you’re sure you don’t want the function to raise exceptions.
2. Use an ‘int’ return type on the function to allow an error code to be returned.
performance hint: anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx:104:5: Exception check on ‘c_error_callback’ will always require the GIL to be acquired.
Possible solutions:
1. Declare the function as ‘noexcept’ if you control the definition and you’re sure you don’t want the function to raise exceptions.
2. Use an ‘int’ return type on the function to allow an error code to be returned.
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 install Cython==3.0.0a10
2. No such file or directory: ‘patchelf’
sudo apt-get install patchelf