python 导入环境OpenAI Gym出错

djmepvbi  于 2023-03-28  发布在  Python
关注(0)|答案(6)|浏览(182)

我正在尝试运行OpenAI Gym环境,但收到以下错误:

import gym
env = gym.make('Breakout-v0')

错误

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ale_py/gym/environment.py:11: DeprecationWarning: Importing atari-py roms won't be supported in future releases of ale-py.
  import ale_py.roms as roms
A.L.E: Arcade Learning Environment (version +a54a328)
[Powered by Stella]
Traceback (most recent call last):
  File "/Users/username/Desktop/OpenAI Gym Stuff/OpenAI_Exp.py", line 2, in <module>
    env = gym.make('Breakout-v0')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gym/envs/registration.py", line 200, in make
    return registry.make(id, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gym/envs/registration.py", line 105, in make
    env = spec.make(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gym/envs/registration.py", line 75, in make
    env = cls(**_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ale_py/gym/environment.py", line 123, in __init__
    self.seed()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ale_py/gym/environment.py", line 171, in seed
    raise error.Error(
gym.error.Error: Unable to find game "Breakout", did you import Breakout with ale-import-roms?
kulphzqa

kulphzqa1#

pip install gym[atari,accept-rom-license]==0.21.0
fquxozlt

fquxozlt2#

这对我通过终端工作:

pip install gym[atari]
pip install autorom[accept-rom-license]

安装gym后是80个游戏,安装gym[atari]后是267个游戏,而且你必须接受特定的许可证才能激活额外的游戏。

mi7gmzs6

mi7gmzs63#

代码对gym0.18.00.19.0有效,但对0.20.0无效
您可以使用

pip install --upgrade gym==0.19.0

顺便说一句:它可能还需要安装gym[atari]gym[all]才能让所有元素工作。
根据Release Note for 0.21.0中的信息(在pip上还没有准备好,但可以从GitHub安装),ALEArcade Learning Environment)中有一些变化,它造成了所有问题,但在0.21.0中得到了修复。

  • 旧的雅达利入口点,这是打破了与最后一个版本和升级到ALE-Py是固定的
    但是新的gym[atari]不安装ROM,您需要使用模块AutoROM
    -pip install gym[atari]不再分发ALE(Atari模拟器)运行各种游戏所需的Atari ROM。将ROM安装到ALE中的最简单方法是使用AutoROM。

编辑:

安装后,GitHub上的0.21.0版本对我有效
(it可能需要程序git

pip install --upgrade git+https://github.com/openai/gym
pip install autorom

AutoRom    

pip install --upgrade gym[atari]

AutoRom运行程序,询问您是否有ROM许可证并在AutoROM/roms中安装ROM,但我不必将ROM移动到其他地方。

AutoROM will download the Atari 2600 ROMs.
They will be installed to:
    /usr/local/lib/python3.8/dist-packages/AutoROM/roms

Existing ROMs will be overwritten.

I own a license to these Atari 2600 ROMs.
I agree to not distribute these ROMs and wish to proceed: [Y/n]:

Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/adventure.bin                                                                                                                           
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/air_raid.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/alien.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/amidar.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/assault.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/asterix.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/asteroids.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/atlantis.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/atlantis2.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/backgammon.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/bank_heist.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/basic_math.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/battle_zone.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/beam_rider.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/berzerk.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/blackjack.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/bowling.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/boxing.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/breakout.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/carnival.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/casino.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/centipede.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/chopper_command.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/combat.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/crazy_climber.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/crossbow.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/darkchambers.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/defender.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/demon_attack.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/donkey_kong.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/double_dunk.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/earthworld.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/elevator_action.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/enduro.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/entombed.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/et.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/fishing_derby.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/flag_capture.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/freeway.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/frogger.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/frostbite.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/galaxian.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/gopher.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/gravitar.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/hangman.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/haunted_house.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/hero.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/human_cannonball.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/ice_hockey.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/jamesbond.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/journey_escape.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/joust.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/kaboom.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/kangaroo.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/keystone_kapers.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/king_kong.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/klax.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/koolaid.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/krull.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/kung_fu_master.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/laser_gates.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/lost_luggage.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/mario_bros.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/maze_craze.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/miniature_golf.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/montezuma_revenge.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/mr_do.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/ms_pacman.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/name_this_game.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/othello.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/pacman.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/phoenix.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/pitfall.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/pitfall2.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/pong.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/pooyan.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/private_eye.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/qbert.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/riverraid.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/road_runner.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/robotank.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/seaquest.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/sir_lancelot.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/skiing.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/solaris.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/space_invaders.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/space_war.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/star_gunner.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/superman.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/surround.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/tennis.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/tetris.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/tic_tac_toe_3d.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/time_pilot.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/trondead.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/turmoil.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/tutankham.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/up_n_down.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/venture.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/video_checkers.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/video_chess.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/video_cube.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/video_pinball.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/warlords.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/wizard_of_wor.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/word_zapper.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/yars_revenge.bin
Installed /usr/local/lib/python3.8/dist-packages/AutoROM/roms/zaxxon.bin
Done!

安装后,这段代码为我工作,没有错误,没有DeprecationWarning

import gym
import ale_py

print('gym:', gym.__version__)
print('ale_py:', ale_py.__version__)

env = gym.make('Breakout-v0')

它给了

gym: 0.21.0
ale_py: 0.7.1

A.L.E: Arcade Learning Environment (version +b7b0c1a)
[Powered by Stella]
dluptydi

dluptydi4#

对于在2023中使用新Gymnasium fork的任何人,我已经在我的mac上使用以下步骤本地设置了Breakout
1.创建具有以下依赖项的requirements.txt文件:

gymnasium[atari, all]

 swig

 Box2D

 box2d-kengz

 pygame

 ale_py

 autorom

1.通过运行以下命令创建python虚拟环境并安装依赖项:

python3 -m venv .venv

 source .venv/bin/activate

 pip install -r requirements.txt

1.运行以下命令以接受许可证

AutoROM --accept-license

如果你在这个步骤中遇到任何超时问题,请查看这个github问题以获得一些提示。
1.运行以下python代码以启动环境

import gymnasium as gym
 import ale_py

 from gymnasium.utils import play

 print('gym:', gym.__version__)

 print('ale_py:', ale_py.__version__)

 env = gym.make("ALE/Breakout-v5", render_mode="rgb_array")

 play.play(env, zoom=3)

1.按space开始游戏和sd来控制它。
好好享受吧!

e1xvtsh3

e1xvtsh35#

它可以用conda来解决:
1.安装健身房版本0.19.0,通过,

conda install -c conda-forge gym=0.19.0;

1.安装atari_py通过

conda install -c conda-forge atari_py;

1.下载Roms,然后解压缩RAR。
1.打开终端,激活环境,然后输入:

python -m atari_py.import_roms \<path to folder\>,

这将把指定文件夹中的ROM复制到pkg文件夹。

lf5gs5x2

lf5gs5x26#

这可以用较新的gym来实现(在我的例子中是windows环境下的0.24.0)。下载ROM(通过AutoROM)并通过ale-import-roms安装ROM后,您需要将环境变量ALE_PY_ROM_DIR设置为bin的目录。
在python中(在我的例子中是Jupyter -当然,环境变量必须事先定义),你需要:

from ale_py import ALEInterface
ale = ALEInterface()

在此之后,您可以(使用名称空间ALE/),例如:

from ale_py.roms import SpaceInvaders
ale.loadROM(SpaceInvaders)
env = gym.make('ALE/SpaceInvaders-v5')

相关问题