A record for WLS2 Ubuntu20.04 to Install mujoco210+mujoco_py with pytorch / tf2

A record for WLS2 Ubuntu20.04 to Install mujoco210+mujoco_py with pytorch / tf2

0 intro.

If you want to use mujoco and mujoco_py with windows 10/11, the best way is to try wsl2! Unlike some old articles said that “wsl is a fake linux env, don’t use it”, now wsl2 is the first choice to dev ML/DL/RL proects. The reasons are:

  1. Based on hyper-V --guarantee the performace.
  2. Can use GPU! --As long as you down load nvidia drive for windows (don’t need to do it again in wsl). VMWare can’t.
  3. Very similar to real linus os --I can’t tell them.
  4. CUDA toolkit has supported WSL-Ubuntu! --don’t worry about cuda&cudnn.

Here is the article >>click<< I recommend to follow to build you own DL env (cuda toolkit, cudnn, docker-gpu, pytorch-gpu, tf2-gpu) with wsl. It can let you have basic pytorch-gpu & tf2-gpu envs.

conda create -n mjc-tf2 python==3.8
conda activate mjc-tf2
pip install tensorflow
python
>>> import tensorflow as tf
>>> tf.config.list_physical_devices()
...
...
Your kernel may have been built without NUMA support.
[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'), PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
>>> quit()

1 mujoco210

mujoco210 is the latest version. I can’t install mujoco-py with mujoco150, so I use it.

wget https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz
mkdir ~/.mujoco
tar –xvzf mujoco210-linux-x86_64.tar.gz –C ~/.mujoco
vim ~/.bashrc

Add a line : export LD_LIBRARY_PATH=~/.mujoco/mujoco210/bin

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

Wow! Your first reward.
在这里插入图片描述

2 mujoco-py

It is the most terrible step, if you try to install mujoco150 version both on windows / wsl (waste me 1 day). But, with mujoco210, it’s easy.

conda activate mjc-tf2
sudo apt update
sudo apt-get install patchelf
sudo apt-get install python3-dev build-essential libssl-dev libffi-dev libxml2-dev
sudo apt-get install libxslt1-dev zlib1g-dev libglew1.5 libglew-dev python3-pip

git clone https://github.com/openai/mujoco-py
cd mujoco-py
pip install -r requirements.txt
pip install -r requirements.dev.txt
pip3 install -e . --no-cache

sudo apt install libosmesa6-dev libgl1-mesa-glx libglfw3
pip install Cython==3.0.0a10
pip3 install -U 'mujoco-py<2.2,>=2.1'
cd examples  (in mujoco-py file)
python3 setting_state.py

But I still can see the screem, I need sth to do next.

3 VcXsrv Windows X Server

>>click it<< You need this visualization tool.

sudo apt install libgl1-mesa-dev freeglut3-dev libglu1-mesa-dev
sudo apt install libsoil-dev libglm-dev libassimp-dev libglew-dev libglfw3-dev libxinerama-dev libxcursor-dev libxi-dev
export DISPLAY=:0.0
sudo apt install x11-apps mesa-utils
glxgears

python3 setting_state.py

mujoco_py is done!
在这里插入图片描述

4 Try mujoco with gym

I install mujoco for using it in gym, so I need to try them together.

pip install gym[all]

Run a test code:

import gym
import mujoco_py

env = gym.make('Humanoid-v4',render_mode='human')
obs = env.reset()

for _ in range(1000):
    action = env.action_space.sample()
    obs, reward, done,_, info = env.step(action)
    if done:
        obs = env.reset()
    env.render()
env.close()

The result is like this:
在这里插入图片描述

summary

It’s a hard war to me. I even reinstalled my computer, because of some “Absurd Environmental Dependency Issue”, e.g. my file path is to long which is limited in 260 in windows. It takes me a lot of time to deal with dependncies!! (That is also why I dislike Python.) I still need to work on sth:

  1. Run mbpo code
    • The code’s version is quite old.
    • I need to dive into it and replace all the old APIs with new ones.
    • Make sure it can run in my env.
  2. Reed papers
  3. Have a good sleep…

refs

Thanks to all these articles. You need to read the latest tutorials, or you will turned to despair.

  • https://zhuanlan.zhihu.com/p/535806578
  • https://blog.csdn.net/CCCDeric/article/details/131788795
  • https://blog.csdn.net/weixin_41231535/article/details/124974794
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值