美文网首页实验室日常
如何安装强化学习虚拟环境Gym,Mujoco,Mujoco-py

如何安装强化学习虚拟环境Gym,Mujoco,Mujoco-py

作者: Lutein | 来源:发表于2018-03-03 15:10 被阅读924次
    mjpro150 mujoco-py 1.50.1 Gym 0.9.6
    mjpro131 mujoco-py 1.3 Gym 0.9.3

    环境:Ubuntu 16.04, Cuda 9.1, nvidia-390, Python 3.5.2
    安装顺序:Mujoco, Mujoco-py, Gym

    Mujoco

    • source: https://www.roboti.us/index.html
    • version: mjpro150
    • 获取license:学生可通过教育邮箱获取一年免费license,在mjkey.txt中。同一个license可用于131,140,150版本的Mujoco
    #download mjpro150.zip
    wget -O mjpro150.zip https://www.roboti.us/download/mjpro150_linux.zip
    mkdir ~/.mujoco
    unzip mjpro150.zip -d ~/.mujoco/mjpro150
    #put the license file into ~/.mujoco & ~/.mujoco/mjpro150/bin
    cp mjkey.txt ~/.mujoco
    cp mjkey.txt ~/.mujoco/mjpro150/bin
    #test
    cd ~/.mujoco/mjpro150/bin
    ./simulate ../model/humanoid.xml
    

    测试完后将~/.mujoco/mjpro150/bin添加到LD_LIBRARY_PATH中,~/.mujoco添加到MUJOCO_KEY_PATH

    Mujoco-py

    #install dependencies
    sudo apt-get update -q
    DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
    curl \
    git \
    libgl1-mesa-dev \
    libgl1-mesa-glx \
    libosmesa6-dev \
    python3-pip \
    python3-numpy \
    python3-scipy \
    unzip \
    vim \
    wget \
    xpra \
    xserver-xorg-dev
    sudo apt-get clean
    sudo rm -rf /var/lib/apt/lists/*
    #install patchelf
    sudo curl -o /usr/local/bin/patchelf https://s3-us-west-2.amazonaws.com/openai-sci-artifacts/manual-builds/patchelf_0.9_amd64.elf
    sudo chmod +x /usr/local/bin/patchelf
    #download mujoco-py
    git clone https://github.com/openai/mujoco-py.git
    

    在我的配置环境下,如果直接安装或在此时通过源码编译后在import时会报GLEW initalization error: Missing GL version,按照https://github.com/openai/mujoco-py/issues/44中的回复,这是mujoco-py这一版本的问题,可以按照对应版本将其降到1.3,同时对应的mujocoGym版本也要改变。在此按照https://github.com/openai/mujoco-py/pull/145/files中的方法改变/mujoco-py/mujoco-py/builder.py文件后,再进行安装。

    #install mujoco-py
    cd mujoco-py
    sudo python3 setup.py install
    #test
    python3
    import mujoco_py
    from os.path import dirname
    model = mujoco_py.load_model_from_path(dirname(dirname(mujoco_py.__file__))  +"/xmls/claw.xml")
    sim = mujoco_py.MjSim(model)
    
    print(sim.data.qpos)
    # [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
    
    sim.step()
    print(sim.data.qpos)
    # [  2.09217903e-06  -1.82329050e-12  -1.16711384e-07  -4.69613872e-11
    #   -1.43931860e-05   4.73350204e-10  -3.23749942e-05  -1.19854057e-13
    #   -2.39251380e-08  -4.46750545e-07   1.78771599e-09  -1.04232280e-08]
    

    注意: 此时尚不能跑通例程,因为可视化时渲染还是会报错,需要使用LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so:/usr/lib/nvidia-390/libGL.so

    #test for visualization
    cd mujoco-py/examples
    LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so:/usr/lib/nvidia-390/libGL.so python3 body_interaction.py
    
    body_interaction渲染结果

    Gym

    #download source code
    git clone https://github.com/openai/gym.git
    cd gym
    #install requirements
    sudo apt-get install -y python-numpy python-dev cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl libboost-all-dev libsdl2-dev swig
    #install gym (full-version)
    sudo pip3 install -e .
    #install particular model
    sudo pip3 install -e '.[box2d]'
    

    reference

    https://www.jianshu.com/p/9b9247bf6ccb
    https://github.com/openai/mujoco-py/pull/145
    https://github.com/openai/mujoco-py/issues/44

    相关文章

      网友评论

      • 杉shan:请问楼主有没有遇到过AttributeError: 'module' object has no attribute 'load_model_from_path'
        这个错误。。。我是在python中测试mujoco_py 时执行model = mujoco_py.load_model_from_path(dirname(dirname(mujoco_py.__file__)) +"/xmls/claw.xml")得到的这个错误~~~~~~~
        0da984715ded:@杉shan 请问您是怎么解决这个问题? 我也碰到了这个问题。
        杉shan:@Lutein 有人也报错,但是再更改了gym的版本号之后就正常了,mujoco131 + mujoco_py 0.5.7 + gym 0.7.4 可我这里还是报错::fearful:
        Lutein:我试了下不会报这个错,你去mujoco-py的GitHub页面issue里搜搜看别人有没有这个错?
      • fendoudelvye:如果方便,希望能交流一下,能否给一个邮箱,我的邮箱是1183030053@qq.com.
      • fendoudelvye:我看官方的Dockerfile中的操作和您给出的操作,
        ENV LANG C.UTF-8

        RUN mkdir -p /root/.mujoco \
        && wget https://www.roboti.us/download/mjpro150_linux.zip -O mujoco.zip \
        && unzip mujoco.zip -d /root/.mujoco \
        && rm mujoco.zip
        COPY ./mjkey.txt /root/.mujoco/
        ENV LD_LIBRARY_PATH /root/.mujoco/mjpro150/bin:$LD_LIBRARY_PATH

        COPY vendor/Xdummy /usr/local/bin/Xdummy
        RUN chmod +x /usr/local/bin/Xdummy
        不知这些什么意思?
        Lutein:@fendoudelvye 您不会用Linux吗?这些都是Linux命令行语句
      • 海街diary:请问博主,那个mjkey..txt长什么样子呢?官方只给我发的一个激活码
        海街diary:@Lutein 谢谢!
        Lutein:@海街diary 在mujoco官网上,那个license里面,第三步,输入你的激活码和电脑ID,按照它步骤走就可以了

      本文标题:如何安装强化学习虚拟环境Gym,Mujoco,Mujoco-py

      本文链接:https://www.haomeiwen.com/subject/buwtfftx.html