【mujoco】Ubuntu20.04 configuration mujoco210

【mujoco】Ubuntu20.04 configuration mujoco210

This article briefly introduces how to configure in the ubuntu20.04 system for reinforcement learning. mujoco210

1. Install mujoco210

Found in official resourceshttps://github.com/google-deepmind/mujoco/releases/tag/2.1.0

Image

Download, then find the download path and decompress it.

cd 你的存放路径
tar -xvf ./mujoco210-linux-x86_64.tar.gz 
sudo mkdir ~/.mujoco			#在主目录下创建.mujoco
mv ./mujoco210 ~/.mujoco 		#将mujoco210放置在~/.mujoco中

Then configure the environment variables

sudo gedit ~/.bashrc

Add the following two lines at the end of.bashrc

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sjh/.mujoco/mujoco210/bin		

Pay attention to the path problem here, please change it to your own user name/home/你的用户名/...

source ~/.bashrc

Then you can test it

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

If the following results appear, it indicates that there is no problem with the configuration.

Image

2. Install mujoco-py

Top of the neckmujoco-py Minamoto https://github.com/openai/mujoco-py

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

Then installmujoco-py into your own virtual environment. For the convenience of demonstration, I will create a new virtual environment heremujo

conda create mujo python=3.8
conda activate mujo

then installmujoco-py

cd 你下载mujo的路径
pip3 install -U 'mujoco-py<2.2,>=2.1'
pip3 install -r requirements.txt
pip3 install -r requirements.dev.txt
python3 setup.py install

Then configure the environment variables

sudo gedit ~/.bashrc

Add to

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia 

Test whether the installation is successful

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]

If the output is as follows, the installation is successful

Iamge

3. An error occurs when using render

The error is reported as follows

ERROR: GLEW initalization error: Missing GL version

We need to edit the environment variables again

sudo gedit ~/.bashrc

join in

export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so

To solve the problem, run the sample code as follows

import gym

# 创建 HalfCheetah 环境
env = gym.make('HalfCheetah-v3')

# 查看状态空间和动作空间的维度
print("状态空间维度:", env.observation_space.shape)
print("动作空间维度:", env.action_space.shape)

# 初始化环境
observation = env.reset()

# 运行环境并查看结果
for _ in range(1000):  # 你可以根据需要设置运行的步数
    env.render()  # 可视化环境
    action = env.action_space.sample()  # 随机采样动作,实际中需要用你的智能体来生成动作
    observation, reward, done, _ = env.step(action)

    if done:
        observation = env.reset()  # 如果达到终止条件,重新初始化环境

env.close()  # 关闭环境窗口
Iamge

Reference

Ubuntu20.04 installation mujoco
RL environment configuration: ERROR: GLEW initalization error: Missing GL version

Guess you like

Origin blog.csdn.net/qq_44940689/article/details/134419463