Hindsight Experience Replay (HER)复现
本文记录了安装OpenAI Gym环境的踩坑过程,重点解决Python 3.5.2版本兼容、Gym 0.20.0依赖冲突等问题。针对conda环境配置、mujoco_py编译失败等常见错误,提供了添加conda-forge通道、安装GCC开发库等解决方案。同时分享了FetchPush-v1等环境的训练和演示命令,帮助开发者快速搭建强化学习实验环境。适用于Ubuntu/Windows系统,包含从基础
·
本文又称openai gym安装血泪史
代码
避坑指南
注:
- gym:https://github.com/openai/gym/tree/v0.20.0
- 环境:Ubuntu22.04/Windows10
- python:3.9
环境配置
- 第一次用的版本是python3.5,发现要求python环境为3.5,但anaconda版本太新,装不了3.5.2
PackagesNotFoundError: The following packages are not available from current channels:
- python=3.5.2
Current channels:
- defaults
解决方法:
添加conda-forge通道:执行以下命令,将conda-forge(社区维护的扩展仓库)添加到conda配置中,该通道通常包含旧版本包:
conda config --add channels conda-forge
conda config --set channel_priority strict
或者
conda create --name training python=3.5.2 -c conda-forge
或者手动安装Python 3.5.2,安装后通过conda管理环境:
conda create --name training python=3.5.2
- 安装gym
前置条件需安装scipy和numpy等等,需要注意版本对应
- 包太旧不支持下载
前往pypi下载对应版本的包
Ubuntu
Ubuntu可能会有其他的问题。
- 安装完mujoco后需要修改path
nano ~/.bashrc
然后添加
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/自己的用户名/.mujoco/mjpro150/bin
- mujoco_py setup失败
一片其他具体报错。。。
error: command 'gcc' failed: No such file or directory
- GCC未安装或未正确配置。 执行gcc --version 如果命令失败或未返回版本信息,说明GCC未安装。运行 sudo apt update && sudo apt install gcc g++ 进行安装。
- 缺少关键开发库。运行以下命令安装全套依赖: sudo apt install libgl1-mesa-dev libgl1-mesa-glx libglew-dev libosmesa6-dev patchelf。
- 系统环境不完整。运行 sudo apt install build-essential pkg-config 确保基础编译环境完整。
gym安装
如果下载gym0.20,会发现需要的atari-py=0.2.6被弃用了,可以用0.2.9,然后修改setup.py
pip install -e .
Obtaining file:gym-0.20.0
Installing build dependencies ... done
Checking if build backend supports build_editable ... done
Getting requirements to build editable ... error
error: subprocess-exited-with-error
× Getting requirements to build editable did not run successfully.
│ exit code: 1
╰─> [3 lines of output]
/tmp/pip-build-env-z6v1vgsv/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py:289: UserWarning: Unknown distribution option: 'tests_require'
warnings.warn(msg)
error in gym setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed to build 'file:gym-0.20.0' when getting requirements to build editable
结果发现是把setup.py中的"opencv-python>=3.“改为"opencv-python>=3"就行,去掉”."
mujoco-py与numpy2不兼容
File "mujoco_py/cymj.pyx", line 1, in init mujoco_py.cymj
ValueError: numpy.dtype size changed, may indicate binary
incompatibility. Expected 96 from C header, got 88 from PyObject
最简单就是安装numpy=1.26
train
example:
python train.py --env-name='FetchPush-v1' --cuda(看是否有gpu) 2>&1 | tee push.log
具体参数可以看arguments.py
demo:
python demo.py --env-name=<environment name>

更多推荐



所有评论(0)