Mujoco210和Mujoco-py的安装

Mujoco210和Mujoco-py的安装

文章目录

  • 前言
  • 一、mujoco210安装
  • 二、安装mujoco-py
  • 三、出现bug
  • 四、参考链接


前言

讲一下我安装mujoco210以及mujoco-py的过程以及遇到的bug


一、mujoco210安装

1.安装MuJoCo

# 下载压缩档 
https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz
# 上传到服务器
scp C:\Users\Owner\Downloads\mujoco210-linux-x86_64.tar.gz  g7:/home/chenwenze19
# 创建文件夹
mkdir ~/.mujoco
# 解压缩
tar -zxvf mujoco210-linux-x86_64.tar.gz -C ~/.mujoco

添加环境变量

gedit ~/.bashrc
export LD_LIBRARY_PATH=~/.mujoco/mujoco210/bin
source ~/.bashrc

测试mujoco

cd ~/.mujoco/mujoco210/bin
./simulate ../model/humanoid.xml

二、安装mujoco-py

2.1 下载mujoco-py到本地电脑

git clone https://github.com/openai/mujoco-py.git

2.2 创建anaconda环境然后进行安装
这里我创建了一个名为pytorch的python版本为3.8的环境

conda create -n pytorch python=3.8
conda activate pytorch
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

2.3 配置.bashrc环境文件

gedit ~/.bashrc
# 在最后添加下面代码然后保存退出文档
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/zsq/.mujoco/mujoco210/bin:/usr/lib/nvidia
source ~/.bashrc

2.4 测试mujoco-py安装是否成功

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]

三、出现bug

3.1 出现问题,报错fatal error: GL/glew.h: No such file or directory导致command ‘gcc‘ failed with exit status 1
解决方法便是依次执行以下命令:

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

3.2 出现问题:No such file or directory: ‘patchelf’
安装patchelf就可以解决

sudo apt-get update -y
sudo apt-get install -y patchelf

四、参考链接

[1]https://zhuanlan.zhihu.com/p/361527296
[2]https://blog.csdn.net/qq_47997583/article/details/125400418

你可能感兴趣的:(mujoco,gym,linux,python,人工智能)