You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS6.5部署OpenAI Gym环境时Box2D-kengz安装报错求助

在CentOS 6.5上部署OpenAI Gym环境的问题与解决

我之前在CentOS 6.5上部署OpenAI Gym时,碰到了和你一模一样的问题——就在执行pip install '.[all]'时卡在了Box2D-kengz的编译环节。下面我把完整的安装流程、遇到的错误以及解决办法整理出来:

初始安装步骤

我一开始是按照以下流程操作的:

  • 安装Anaconda:先下载安装包再执行安装脚本
    wget --no-check-certificate https://repo.anaconda.com/archive/Anaconda3-5.1.0-Linux-x86_64.sh
    bash Anaconda3-5.1.0-Linux-x86_64.sh
    
  • 创建虚拟环境:
    conda create --name gymlab python=3.6
    
  • 安装Gym:
    1. 激活虚拟环境:
      source activate gymlab
      
    2. 克隆Gym仓库:
      git clone https://github.com/openai/gym.git
      
    3. 进入仓库目录:
      cd gym
      
    4. 尝试安装全量依赖:
      pip install '.[all]'
      

遇到的编译错误

执行最后一步时,出现了Box2D-kengz的编译失败,完整错误输出如下:

Processing /root/gym
Requirement already satisfied: numpy>=1.10.4 in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from gym==0.10.5) (1.14.3)
Requirement already satisfied: requests>=2.0 in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from gym==0.10.5) (2.18.4)
Requirement already satisfied: six in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from gym==0.10.5) (1.11.0)
Requirement already satisfied: pyglet>=1.2.0 in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from gym==0.10.5) (1.3.2)
Requirement already satisfied: atari_py>=0.1.1 in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from gym==0.10.5) (0.1.1)
Requirement already satisfied: Pillow in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from gym==0.10.5) (5.1.0)
Requirement already satisfied: PyOpenGL in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from gym==0.10.5) (3.1.0)
Collecting Box2D-kengz (from gym==0.10.5)
Using cached https://files.pythonhosted.org/packages/81/20/51d6c0c87f7642efb709c518fb0ca8e5eab068259588552c41da5926ae27/Box2D-kengz-2.3.3.tar.gz
Collecting mujoco_py>=1.50 (from gym==0.10.5)
Collecting imageio (from gym==0.10.5)
Using cached https://files.pythonhosted.org/packages/a7/1d/33c8686072148b3b0fcc12a2e0857dd8316b8ae20a0fa66c8d6a6d01c05c/imageio-2.3.0-py2.py3-none-any.whl
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from requests>=2.0->gym==0.10.5) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from requests>=2.0->gym==0.10.5) (2018.4.16)
Requirement already satisfied: idna<2.7,>=2.5 in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from requests>=2.0->gym==0.10.5) (2.6)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from requests>=2.0->gym==0.10.5) (1.22)
Requirement already satisfied: future in /root/anaconda3/envs/gymlab/lib/python3.6/site-packages (from pyglet>=1.2.0->gym==0.10.5) (0.16.0)
Collecting glfw>=1.4.0 (from mujoco_py>=1.50->gym==0.10.5)
Collecting cffi>=1.10 (from mujoco_py>=1.50->gym==0.10.5)
Using cached https://files.pythonhosted.org/packages/6d/c0/47db8f624f3e4e2f3f27be03a93379d1ba16a1450a7b1aacfa0366e2c0dd/cffi-1.11.5-cp36-cp36m-manylinux1_x86_64.whl
Collecting Cython>=0.27.2 (from mujoco_py>=1.50->gym==0.10.5)
Using cached https://files.pythonhosted.org/packages/19/eb/c4d9f3beafd5ac0615936860bcee41d93ca58f8734a16715da0037d2c468/Cython-0.28.2-cp36-cp36m-manylinux1_x86_64.whl
Collecting pycparser (from cffi>=1.10->mujoco_py>=1.50->gym==0.10.5)
Building wheels for collected packages: gym, Box2D-kengz
Running setup.py bdist_wheel for gym ... done
Stored in directory: /tmp/pip-ephem-wheel-cache-or4iim1z/wheels/6e/18/10/1234738b0aafab3f8f70d61d2763dc3efda78a41d153584dee
Running setup.py bdist_wheel for Box2D-kengz ... error
Complete output from command /root/anaconda3/envs/gymlab/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-5jh8n6q7/Box2D-kengz/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-ckydr3cn --python-tag cp36:
Using setuptools (version 39.1.0).
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/Box2D

问题分析

这个问题的核心原因是CentOS 6.5自带的GCC版本太低(默认是4.4.7),而Box2D-kengz的编译需要用到C++11特性,老版本的GCC不支持这些特性,导致编译失败。另外,系统可能还缺少一些必要的图形和编译依赖库。

解决步骤

1. 升级GCC版本到支持C++11的版本

CentOS 6.5可以通过SCL(Software Collections)安装更高版本的GCC:

# 安装SCL源
yum install -y centos-release-scl
# 安装GCC 4.8(支持C++11)
yum install -y devtoolset-3-gcc devtoolset-3-gcc-c++
# 激活新版本GCC(临时生效,重启终端后需要重新激活)
scl enable devtoolset-3 bash
# 如果需要永久生效,把下面的命令添加到~/.bashrc末尾
echo "source /opt/rh/devtoolset-3/enable" >> ~/.bashrc

2. 安装系统依赖库

安装编译Box2D和Gym所需的系统依赖:

yum install -y cmake libX11-devel mesa-libGL-devel

3. 替换Box2D-kengz为官方维护的包

Box2D-kengz是第三方修改版,容易出现兼容性问题,建议改用官方维护的box2d-py:

# 先卸载残留的Box2D-kengz
pip uninstall -y Box2D-kengz
# 安装官方Box2D包
pip install box2d-py

4. 重新安装Gym

回到Gym目录,重新执行安装命令:

cd gym
# 如果不需要Mujoco(需要付费许可证),可以只安装基础和常用环境
pip install '.[classic_control,box2d]'
# 如果确实需要全量安装(注意Mujoco需要单独配置许可证)
pip install '.[all]'

额外提示

如果不需要Mujoco相关的环境,建议只安装必要的部分,避免不必要的麻烦。另外,CentOS 6.5已经停止维护,后续可能会遇到更多依赖兼容性问题,如果条件允许,建议升级到CentOS 7或更高版本。

内容的提问来源于stack exchange,提问作者Jackon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:23:35