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:
- Based on hyper-V --guarantee the performace.
- 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.
- Very similar to real linus os --I can’t tell them.
- 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:
- 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.
- Reed papers
- 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