简体   繁体   English

导入环境OpenAI Gym报错

[英]Error in importing environment OpenAI Gym

I am trying to run an OpenAI Gym environment however I get the following error:我正在尝试运行 OpenAI Gym 环境,但出现以下错误:

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

ERROR错误

/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?

Code works for me with gym 0.18.0 and 0.19.0 but not with 0.20.0代码适用于gym 0.18.00.19.0但不适用于0.20.0

You may downgrade it with您可以将其降级

pip install --upgrade gym==0.19.0

BTW: it may also need to install gym[atari] or gym[all] to have all elements to work.顺便说一句:它可能还需要安装gym[atari]gym[all]才能使所有元素正常工作。


Base on information in Release Note for 0.21.0 (which is not ready on pip but you can install from GitHub) there was some change in ALE ( Arcade Learning Environment ) and it made all problem but it is fixed in 0.21.0 .根据 0.21.0 发行说明中的​​信息(尚未在pip准备好,但您可以从 GitHub 安装)中的信息在ALEArcade Learning Environment )中发生了一些变化,它导致了所有问题,但在0.21.0中得到了0.21.0

-The old Atari entry point that was broken with the last release and the upgrade to ALE-Py is fixed - 旧的 Atari 入口点在上一个版本和升级到 ALE-Py 时被破坏了

But new gym[atari] not installs ROMs and you will need to use module AutoROM但是新的gym[atari]不安装ROM,你需要使用AutoROM模块

-pip install gym[atari] no longer distributes Atari ROMs that the ALE (the Atari emulator used) needs to run the various games. -pip installgym[atari] 不再分发 ALE(使用的 Atari 模拟器)运行各种游戏所需的 Atari ROM。 The easiest way to install ROMs into the ALE has been to use AutoROM.将 ROM 安装到 ALE 的最简单方法是使用 AutoROM。


EDIT:编辑:

Version 0.21.0 from GitHub works for me after installing安装后,GitHub 的0.21.0版对我0.21.0

(it may need program git for it) (它可能需要git程序)

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

AutoRom    

pip install --upgrade gym[atari]

AutoRom runs program which asks if you have license for ROMs and install ROMs in AutoROM/roms but I didn't have to move ROMs to other place. 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!

After installation this code works for me without error and without DeprecationWarning .安装后,此代码对我有效,没有错误且没有DeprecationWarning

import gym
import ale_py

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

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

and it gives它给

gym: 0.21.0
ale_py: 0.7.1

A.L.E: Arcade Learning Environment (version +b7b0c1a)
[Powered by Stella]
pip install gym[atari,accept-rom-license]==0.21.0

It can be solved with conda:可以用conda解决:

  1. install gym version 0.19.0, by, conda install -c conda-forge gym=0.19.0;安装健身房版本 0.19.0,通过, conda install -c conda-forgegym=0.19.0;
  2. install atari_py by conda install -c conda-forge atari_py;通过 conda install -c conda-forge atari_py 安装 atari_py;
  3. download the Roms: http://www.atarimania.com/rom_collection_archive_atari_2600_roms.html , and unpack the RAR.下载 Roms: http : //www.atarimania.com/rom_collection_archive_atari_2600_roms.html ,并解压 RAR。
  4. open a terminal, active your environment, and input: python -m atari_py.import_roms <path to folder>, which will copy the ROMs in the folder specified to the pkg folder.打开终端,激活您的环境,然后输入:python -m atari_py.import_roms <path to folder>,这会将指定文件夹中的 ROM 复制到 pkg 文件夹中。

This worked for me via terminal:这通过终端对我有用:

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

After installing gym, it is 80 games.安装健身房后,是80场比赛。 After installing gym[atari], it is 267 games.安装gym[atari]后是267游戏。 And you have to accept the specific licenses to activate additional games.您必须接受特定的许可证才能激活其他游戏。

This can be achieved even with newer gym (in my case 0.24.0 on a windows environment).即使使用较新的健身房也可以实现这一点(在我的例子中是 windows 环境中的 0.24.0)。 After downloading the ROM (via AutoROM) and installing the ROMs via ale-import-roms you need to set the environment variable ALE_PY_ROM_DIR to the directory of the bins.下载 ROM(通过 AutoROM)并通过 ale-import-roms 安装 ROM 后,您需要将环境变量 ALE_PY_ROM_DIR 设置为 bin 目录。

In python (in my case Jupyter - the environment-variable has to be defined beforehand, of course) you need:在 python 中(在我的例子中是 Jupyter - 当然必须事先定义环境变量)你需要:

from ale_py import ALEInterface
ale = ALEInterface()

After this you can (using namespace ALE/) eg在此之后你可以(使用命名空间 ALE/)例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM