Install open source Mujoco on Windows 10

In late April 2022, open source Mujoco and mujoco_py will be installed on Windows 10, the kind that even grandma will install successfully.
First of all, let me explain one thing————————————It is Beijing time——————————

April 19, 2022! ! ! !

Does time have anything to do with installing mujoco? Does timing matter? Answer: It does matter! ! ! Very important! ! ! Why is it important? You have to know that mujoco is open source at the point in time I'm at now, today! ! !
Insert image description here
did you see it? The news that mujoco was open source was released in late October 2021, but DeepMind had just acquired mujoco at this time. It will really be 2022 when mujoco is officially open source. I estimate that mujoco will be truly open source at the end of March or early April of 2022. According to the figure below:
Insert image description here

————For those who are in a hurry, start reading directly from here——————

¥¥¥¥¥¥¥¥¥The above is all nonsense. It is some background knowledge. Now let’s go directly to the main topic and talk about the installation tutorial¥¥¥¥¥¥¥¥

1. Key points of the first step·Background knowledge

mujoco is indeed open source at the time I am at now (17:35 on May 12, 22).

but ! ! ! Does being open source mean that you can install and use mujoco210 under win10? ? The answer is: No! !

That's right, although mujoco is open source, win10 really cannot install the latest version of mujoco210. MAC and Linux systems can install mujoco210, but if you are win10, even now that it is open source, you can only use the mujoco150 version! ! ! Why? Why, you ask? Let me ask you, did you install mujoco for reinforcement learning? If you use mujoco for reinforcement learning, you must also want to use the gym library to import game environments such as Humanoid-v2 and Ant-v2, right? If so, that's right. You know, mujoco≠mujoco_py, and mujoco_py is a product of OpenAI, and the company that bought mujoco was DeepMind. Two different companies, which means there will be problems at the handover.

DeepMind's mujoco210+OpenAI's mujoco_py2.10.14 can be used under Linux and MAC systems, but cannot be used on win10. Please read this sentence from OpenAI on github:
Insert image description here

Insert image description here

Therefore, if you are a Win10 user, please use mujoco 150 honestly. After all, usability is more important than anything else. If you are stubborn and want to force win10 to use mujoco210, then when you use the gym library to call the Humanoid environment, you will definitely get the following error

distutils.errors.CompileError: command ‘D:\VS_IDE\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe’ failed with exit status 2

2. The second step is pre-installation.

I believe you can Baidu like this. You must have installed visual studio, python, pycharm and gym libraries. Don't tell me you haven't installed them (just install them yourself). After these are installed, the mujoco game environment can be called in the gym library.

3. Step 3: Click this link to download the mujoco application

Here is the download link for mujoco *** mujoco ***

1. Click here to download this.
Insert image description here

2. Be sure to create a new folder named .mujoco in the user directory of your C drive (C:\Users\Bright)

Insert image description here

3. Create a mjpro150 folder in the .mujoco file
Insert image description here
4. Extract the downloaded zip into mjpro150
Insert image description here
5. Download the mjkey.txt file, here is the *** download link ***

Click here to download directly. Now that it is open source, there is no need to send an email to apply for a license.

Insert image description here
6. Place the mjkey.txt file into the C:\Users\xxx.mujoco folder and the C:\Users\xxx.mujoco\mjpro150\bin folder
Insert image description here
Insert image description here

7. Add environment variables

Find "User Variables" in "Settings > Environment Variables" on your computer and add two environment variables

Variable name: MUJOCO_PY_MJPRO_PATH
Variable value: C:\Users\xxx.mujoco\mjpro150

Variable name: MUJOCO_PY_MJKEY_PATH
Variable value: C:\Users\xxx.mujoco\mjpro150\bin\mjkey.txt
Insert image description here

Find the Path in "User Variables" in "Settings > Environment Variables" on your computer, double-click, click "New", and enter the address of the bin folder in the mjpro150 file (for example: C:\Users\Bright. mujoco\mjpro150\bin), restart the computer
Insert image description here
. At this point, the mujoco application is successfully installed. After successful installation, you can open simulate.exe in the bin folder, and drag the XML folder in the model folder to the application interface, and the 3D physical simulation of the corresponding model will appear.
Insert image description here

4. The fourth step is to install the python package of mujoco_py

1. Download mujoco_py in github, here is the download link for *** mujoco_py ***

Download this
Insert image description here
2. Unzip the downloaded mujoco_py, copy the mujoco_py folder, and press ctrl+C.
Insert image description here
Paste it into the location of your python virtual environment python package and press ctrl+V.
Insert image description here

5. Step 5: Test and use mujoco

To test, run the following code

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)
sim.step()
print(sim.data.qpos)

If the following picture appears, the installation is considered successful.
Insert image description here

To use mujoco with OpenAI's gym library, enter the following code

#开发者:Bright Fang
#开发时间:2022/5/8 12:33
import gym
# import mujoco
env = gym.make('Humanoid-v2')
env = env.unwrapped
for episode in range(20):
    observation = env.reset() #环境重置
    print(episode)
    # for timestep in range(100):
    while True:
        # print(timestep)
        env.render() #可视化
        action = env.action_space.sample() #动作采样
        observation_, reward, done, info = env.step(action) #单步交互
        # if done:
        #     # print(observation)
        #     print('Episode {}'.format(episode))
        #     break
        observation=observation_
env.close()

You will get the Humanoid game environment using the gym framework, as shown below:
Insert image description here
Want to play ants? use this

import gym
# import mujoco
env = gym.make('Ant-v2')
env = env.unwrapped
for episode in range(20):
    observation = env.reset() #环境重置
    print(episode)
    # for timestep in range(100):
    while True:
        # print(timestep)
        env.render() #可视化
        action = env.action_space.sample() #动作采样
        observation_, reward, done, info = env.step(action) #单步交互
        # if done:
        #     # print(observation)
        #     print('Episode {}'.format(episode))
        #     break
        observation=observation_
env.close()

Want to play something else? Change it yourself
Insert image description here

references:

  1. A tutorial on Zhihu
  2. mujoco official documentation
  3. Another tutorial from Zhihu

Guess you like

Origin blog.csdn.net/fangchenglia/article/details/124286509