Getting an error trying to import environment OpenAI Gym

I am trying to run an OpenAI Gym environment:

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.

>Solution :

Installing the gym as below worked in my environment. (Python 3.7)

pip install "gym[atari, accept-rom-license]"

if you are using 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.

Leave a Reply