链接:https://github.com/deepmind/mujoco/releases/tag/2.1.0
mkdir ~/.mujoco
tar -zxvf mujoco210-linux-x86_64.tar.gz -C ~/.mujoco
gedit ~/.bashrc
在文档最后一行加入下面代码然后保存退出文档
export LD_LIBRARY_PATH=~/.mujoco/mujoco210/bin
source ~/.bashrc
cd ~/.mujoco/mujoco210/bin
./simulate ../model/humanoid.xml
git clone https://github.com/openai/mujoco-py.git
这里我创建了一个名为mujo的python版本为3.8的环境
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
gedit ~/.bashrc
在最后添加下面代码然后保存退出文档
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia
source ~/.bashrc
在pycharm中新建一个python文件并使用前面刚刚创建的环境
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]
这里报环境变量的问题
点击 pycharm中的 Run->Edit Configurations->Environment variables 然后添加变量Name是LD_LIBRARY_PATH
,变量Value是 $LD_LIBRARY_PATH:/home/zsq/.mujoco/mujoco210/bin:/usr/lib/nvidia
注:变量Value中/home之后的下一层为你的用户名我的是zsq这里需要改成你自己的用户名。
出现问题,报错fatal error: GL/glew.h: No such file or directory
导致command ‘gcc‘ failed with exit status 1
参考这个博客解决了:https://blog.csdn.net/qq_32146369/article/details/117374443
解决方法便是依次执行以下命令:
sudo apt-get install build-essential
sudo apt-get install build-essential libgl1-mesa-dev
sudo apt-get install libglew-dev libsdl2-dev libsdl2-image-dev libglm-dev libfreetype6-dev
sudo apt-get install libglfw3-dev libglfw3
参考链接:
https://zhuanlan.zhihu.com/p/488934814
https://zhuanlan.zhihu.com/p/486957504