ubuntu20.04下安装mujoco、mujoco-py、gym

目录

1 安装mujoco

第一步:

之后所有的操作都在 marl 这个环境下进行!!

第二步:

 第三步:

 第四步:测试

2 安装mujoco-py

第一步:

第二步:

第三步:

第四步:测试

3 安装gym

4 可能出现的报错及解决方法:

报错:

报错:

报错:

 报错:

报错:


1 安装mujoco
第一步:

创建一个conda环境:

conda create --name=环境名称 python=3.8

进入该环境:(我定义的环境名称为marl,大家根据各自的环境名称更改指令)

conda activate marl
之后所有的操作都在 marl 这个环境下进行!!
第二步:

进入官网:https://github.com/openai/mujoco-py

点击图中的蓝色Linux下载

ubuntu20.04下安装mujoco、mujoco-py、gym_第1张图片

将下载的文件解压至目录 "~/.mujoco/mujoco210" 中,确保bin等文件在"~/.mujoco/mujoco210" 中

 第三步:

配置.bashrc环境文件

gedit ~/.bashrc

在文档最后一行加入下面代码然后保存退出文档

export LD_LIBRARY_PATH=~/.mujoco/mujoco210/bin

更新配置

source ~/.bashrc
 第四步:测试
cd ~/.mujoco/mujoco210/bin
./simulate ../model/humanoid.xml

若出现下图的界面,则mujoco安装成功

ubuntu20.04下安装mujoco、mujoco-py、gym_第2张图片

2 安装mujoco-py
第一步:

下载mujoco-py,在根目录下,打开终端(确保在marl这个conda环境中)输入

git clone https://github.com/openai/mujoco-py.git
第二步:

依次执行下面的指令进行安装

cd ~/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 ~/.bashrc

在最后添加下面代码然后保存退出文档

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia 

更新配置:

source ~/.bashrc
第四步:测试

依次执行:

cd ~/mujoco-py/examples
python body_interaction.py

若出现下图的界面,则mujoco安装成功 ubuntu20.04下安装mujoco、mujoco-py、gym_第3张图片

3 安装gym
pip install gym
git clone https://github.com/openai/gym

或者

git clone git://github.com/openai/gym

运行代码来添加环境

cd gym
pip install -e .

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

pip install -e .[all]
# 如果超时,换用下面的命令
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 python-dev python3-dev

 再次安装

pip install -e .[all]

若无报错,则gym安装完成 

4 可能出现的报错及解决方法:
报错:

Cython.Compiler.Errors.CompileError: /home/qjm/anaconda3/envs/hiro/lib/python3.8/site-packages/mujoco_py/cymj.pyx

解决方法:

pip install "cython<3"
报错:

ERROR: GLEW initalization error: Missing GL version

解决方法:

sudo gedit ~/.bashrc

在打开的文件最后一行添加:

export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so

保存并关闭,然后执行:

source ~/.bashrc
sudo apt-get install  libglew-dev
sudo apt-get install libglfw3 libglfw3-dev
报错:

缺少GL/osmesa.h文件,由此引起:distutils.errors.CompileError: command ‘gcc’ failed with exit status 1

sudo apt install libosmesa6-dev
 报错:

FileNotFoundError: [Errno 2] No such file or directory: 'patchelf'

sudo apt-get update -y
sudo apt-get install -y patchelf

Python安装第三方库报错:"These Packages Do Not Match The Hashes From The Requirements File."

原因:通常是因为网速问题导致的下载错误,导致对应的哈希值不匹配。

解决方法:需要在pip时,添加"--default-timeout=100000" 

pip install --default-timeout=100000 要安装的库名称
报错:

AttributeError: module ‘gym‘ has no attribute 

卸载gym:

pip uninstall gym

安装低版本gym:

pip install gym==0.9.0 -i https://pypi.douban.com/simple

你可能感兴趣的:(linux,人工智能,ubuntu)