Getting an error trying to import environment OpenAI Gym
题意:尝试导入 OpenAI Gym 环境时遇到错误
问题背景:
I am trying to run an OpenAI Gym environment:
我正在尝试运行一个 OpenAI Gym 环境:
env = gym.make("ALE/Breakout-v5", render_mode="rgb_array")
But I get the following error 但是我得到了以下错误信息:
Traceback (most recent call last):
File "/Users/----/Documents/Spring 2023/----/----/yum.py", line 10, in <module>
env = gym.make("ALE/Breakout-v5", render_mode="rgb_array")
File "/Users/----/anaconda3/envs/----/lib/python3.10/site-packages/gymnasium/envs/registration.py", line 592, in make
_check_version_exists(ns, name, version)
File "/Users/----/anaconda3/envs/----/lib/python3.10/site-packages/gymnasium/envs/registration.py", line 218, in _check_version_exists
_check_name_exists(ns, name)
File "/Users/----/anaconda3/envs/----/lib/python3.10/site-packages/gymnasium/envs/registration.py", line 185, in _check_name_exists
_check_namespace_exists(ns)
File "/Users/----/anaconda3/envs/----/lib/python3.10/site-packages/gymnasium/envs/registration.py", line 180, in _check_namespace_exists
raise error.NamespaceNotFound(f"Namespace {ns} not found. {suggestion_msg}")
gymnasium.error.NamespaceNotFound: Namespace ALE not found. Have you installed the proper package for ALE?
I've looked at all the similar errors that people have discussed online, but I cannot find any fixes that work for me.
我查看了网上讨论的所有类似错误,但找不到任何对我有效的解决方法。
问题解决:
Installing the gym
as below worked in my environment. (Python 3.7)
如下安装 `gym` 在我的环境中有效。(Python 3.7)
pip install "gym[atari, accept-rom-license]"
if you are using gymnasium
:
如果你在使用 `gymnasium`:
pip install "gymnasium[atari, accept-rom-license]"
import gym # or "import gymnasium as gym"
if __name__ == '__main__':
env = gym.make("ALE/Breakout-v5")
A.L.E: Arcade Learning Environment (version 0.8.1+53f58b7)
[Powered by Stella]
If it still doesn't work try adding the following import
如果仍然无效,试试添加以下导入:
import ale_py
# if using gymnasium
import shimmy
import gym # or "import gymnasium as gym"
Remember to create a new empty environment before installation.
记得在安装前创建一个新的空环境。