MuJoCo and mujoco-py Setup on Ubuntu 20.04
MuJoCo and mujoco-py installation instruction(Python 3.X Version)
(Note: Don’t try other Python versions for this tutorial because I don’t promise that it will also be successful.)
This document can help me (maybe you also) to setup MuJoCo and mujoco-py environment when you reinstall your Ubuntu 20.04 every time and can help you save lots of time (at least for me). Note that for mujoco-py, the official Github source from OpenAI only introduced limited setup for related dependent packages or environments that may let you fail to use it. if you follow the instructions below, I promise that 99% you can install the environment on your clean Ubuntu 20.04 successfully (1% may be something wrong with your system itself).
-Last update: 2024.10.10
Step 1: Install anaconda
Anaconda3-2024.06-1-Linux-x86_64.sh (you can install any version later than 2021 based on my tests.)
sudo chmod +x Anaconda3-2024.06-1-Linux-x86_64.sh
./Anaconda3-2024.06-1-Linux-x86_64.sh
Step 2 : install git
sudo apt install git
Step 3 : install the MuJoCo library
-
Download the MuJoCo library fromhttps://mujoco.org/download/mujoco210-linux-x86_64.tar.gz
(Update: now you don’t need to do this, just follow the operations below.)
- create a hidden folder :
sudo mkdir /home/wam/.mujoco
sudo chmod a+rwx /home/wam/.mujoco
(Note: if the folder you created without any permission, use “sudo chmod a+rwx /path/to/file” to give the folder permission)
cd /home/wam/.mujoco
git clone https://github.com/gaolongsen/mujoco210.git
-
include these lines in
.bashrc
file(terminal command: gedit ~/.bashrc):gedit ~/.bashrc
-
Then add the following four lines on the bottom of you
.bashrc
file:
export LD_LIBRARY_PATH=/home/wam/.mujoco/mujoco210/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia
export PATH="$LD_LIBRARY_PATH:$PATH"
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so
(Note that don’t forget to replace the wam
with your local PC name.)
-
source ~/.bashrc
- Test that the library is installed by going into:
cd ~/.mujoco/mujoco210/bin
./simulate ../model/humanoid.xml
If you are successful, you will see like this:
Step 4 Install mujoco-py:
conda create --name mujoco_py python=3.8
conda activate mujoco_py
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
Step 5 reboot your machine
sudo reboot
Step 6 run these commands
conda activate mujoco_py
sudo apt install libosmescd examplesa6-dev libgl1-mesa-glx libglfw3
sudo apt-get install libosmesa6-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libGL.so.1
sudo ln -s /usr/lib/x86_64-linux-gnu/libGL.so
pip3 install -U 'mujoco-py<2.2,>=2.1'
pip install "cython<3"
(PS: above command you don’t have to do if you run the following example test without any error happened. But based on our test, you probably need to downgrade the cython to avoid any potential problem.)
cd examples
python3 setting_state.py
If you successfully setup your environment, you will see the demo run like this:
If you’re getting a Cython error, try:
pip install "cython<3"
Note: if you use Pycharm as your compiler, don’t forget to add this line on Run
-> Edit Configuration
-> Environment variables
:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/wam/.mujoco/mujoco210/bin:/usr/lib/nvidia;LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so
(Note that don’t forget to replace the wam
with your local PC name.)