1 安装mujoco
下载mujoco:https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz
-
- 将下载的文件解压至
/opt/mujoco
中
- 将下载的文件解压至
-
- 添加环境变量:
执行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/
- 添加环境变量:
-
- 更新配置:执行
source /etc/profile
- 更新配置:执行
-
- 测试:
cd /opt/mujoco/mujoco210/bin ./simulate ../model/humanoid.xml
- 测试:
若出现下面画面,则mujoco安装成功
2 安装mujoco_py
-
- 下载mujoco-py:
cd /opt git clone https://github.com/openai/mujoco-py.git
- 下载mujoco-py:
-
- 依次执行下面的指令进行安装
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
- 依次执行下面的指令进行安装
-
- 配置环境文件
在最后添加下面代码然后保存退出文档gedit /etc/profile
更新配置:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia
source /etc/profile
- 配置环境文件
-
- 测试
依次执行:
若出现下图的界面,则mujoco安装成功cd /opt/mujoco-py/examples python3 body_interaction.py
- 测试
-
- 可能遇到的问题
-
问题1: Cython.Compiler.Errors.CompileError: /usr/local/lib/python3.10/dist-packages/mujoco_py/cymj.pyx
解决方法:安装cpyhhonpip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple Cython==3.0.0a10
-
问题2: 缺少GL/osmesa.h文件
解决方案:安装osmesa6sudo apt install libosmesa6-dev
-
问题3:FileNotFoundError: [Errno 2] No such file or directory: ‘patchelf’
解决方案:apt-get install patchelf
3 安装gym
-
- 安装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安装完成