强化学习mujoco gym stable_baseline3 安装教程

1 安装mujoco

下载mujoco:https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz

    1. 将下载的文件解压至/opt/mujoco
    1. 添加环境变量:
      执行 gedit /etc/profile ,打开profile文件,将下面两句话复制到 /etc/profile文件尾部
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mujoco/mujoco210/bin
      export MUJOCO_PY_MUJOCO_PATH=/opt/mujoco/mujoco210/
      
    1. 更新配置:执行source /etc/profile
    1. 测试:
      cd /opt/mujoco/mujoco210/bin
      ./simulate ../model/humanoid.xml
      

若出现下面画面,则mujoco安装成功
在这里插入图片描述

2 安装mujoco_py

    1. 下载mujoco-py:
      	cd  /opt
      	git clone https://github.com/openai/mujoco-py.git
      
    1. 依次执行下面的指令进行安装
      	cd /opt/mujoco-py
      	pip3 install -U 'mujoco-py<2.2,>=2.1'
      	pip3 install -r requirements.txt
      	pip3 install -r requirements.dev.txt
      	python3 setup.py install
      
    1. 配置环境文件
      	gedit /etc/profile
      
      在最后添加下面代码然后保存退出文档
      	export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia 
      
      更新配置:
      	source  /etc/profile
      
    1. 测试
      依次执行:
       	cd /opt/mujoco-py/examples
       	python3 body_interaction.py
      
      若出现下图的界面,则mujoco安装成功
      在这里插入图片描述
    1. 可能遇到的问题
    • 问题1: Cython.Compiler.Errors.CompileError: /usr/local/lib/python3.10/dist-packages/mujoco_py/cymj.pyx
      在这里插入图片描述
      解决方法:安装cpyhhon

      pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple   Cython==3.0.0a10
      
    • 问题2: 缺少GL/osmesa.h文件
      在这里插入图片描述
      解决方案:安装osmesa6

      sudo apt install libosmesa6-dev
      
  • 问题3:FileNotFoundError: [Errno 2] No such file or directory: ‘patchelf’
    在这里插入图片描述
    解决方案:

    apt-get install patchelf
    

3 安装gym

    1. 安装gym:
git clone https://github.com/openai/gym

运行代码来添加环境
接下来安装gym的所有环境,运行以下代码

cd gym
pip install -e .[all]  -i https://pypi.tuna.tsinghua.edu.cn/simple

如果超时,换用下面的命令
如果出现错误:

Building wheels for collected packages: box2d-py, gym
  Building wheel for box2d-py (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      Using setuptools (version 68.0.0).
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-38
      creating build/lib.linux-x86_64-cpython-38/Box2D
      copying library/Box2D/Box2D.py -> build/lib.linux-x86_64-cpython-38/Box2D
      copying library/Box2D/__init__.py -> build/lib.linux-x86_64-cpython-38/Box2D
      creating build/lib.linux-x86_64-cpython-38/Box2D/b2
      copying library/Box2D/b2/__init__.py -> build/lib.linux-x86_64-cpython-38/Box2D/b2
      running build_ext
      building 'Box2D._Box2D' extension
      swigging Box2D/Box2D.i to Box2D/Box2D_wrap.cpp
      swig -python -c++ -IBox2D -small -O -includeall -ignoremissing -w201 -globals b2Globals -outdir library/Box2D -keyword -w511 -D_SWIG_KWARGS -o Box2D/Box2D_wrap.cpp Box2D/Box2D.i
      error: command 'swig' failed: No such file or directory
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for box2d-py
  Running setup.py clean for box2d-py
  Building editable for gym (pyproject.toml) ... done
  Created wheel for gym: filename=gym-0.26.2-0.editable-py3-none-any.whl size=4276 sha256=d500f2aace1313b1e6edeef6688a35cd77a0fe742c6e746285ae58b582fc207b
  Stored in directory: /tmp/pip-ephem-wheel-cache-1rf846yu/wheels/ee/8a/f5/ed98d4005e8172d461a18b6aa8147e52bb0a5dad276b12a2c2
Successfully built gym
Failed to build box2d-py
ERROR: Could not build wheels for box2d-py, which is required to install pyproject.toml-based projects

解决方法:

sudo apt-get install swig build-essential python3-dev

再次安装

pip install -e .[all]

若无报错,则gym安装完成

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值