Farama-Foundation / Gymnasium

An API standard for single-agent reinforcement learning environments, with popular reference environments and related utilities (formerly Gym)
https://gymnasium.farama.org
MIT License
7.46k stars 837 forks source link

NamespaceNotFound: Namespace gym_examples not found #400

Closed jlsvane closed 12 months ago

jlsvane commented 1 year ago

Describe the bug

Hi

Conda environment: see attached yml file as txt

I'm trying to run the custom environment example from url by cloning the git and then following the instructions and installing by "pip install -e ." It fails unless I change the setup file from install_requires=["gym==0.26.0", "pygame==2.1.0"] to this install_requires=["gym>=0.26.0", "pygame>=2.1.0"] when it installs pygame==2.1.0.

When changing this it appears to install. However, when running: import gymnasium import gym_examples env = gymnasium.make('gym_examples/GridWorld-v0')

it fails with this error:

Traceback (most recent call last): File "/home/novelty/gym-examples/grid_test.py", line 10, in env = gymnasium.make('gym_examples/GridWorld-v0') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/novelty/miniconda3/envs/gymnas_test/lib/python3.11/site-packages/gymnasium/envs/registration.py", line 592, in make _check_version_exists(ns, name, version) File "/home/novelty/miniconda3/envs/gymnas_test/lib/python3.11/site-packages/gymnasium/envs/registration.py", line 218, in _check_version_exists _check_name_exists(ns, name) File "/home/novelty/miniconda3/envs/gymnas_test/lib/python3.11/site-packages/gymnasium/envs/registration.py", line 185, in _check_name_exists _check_namespace_exists(ns) File "/home/novelty/miniconda3/envs/gymnas_test/lib/python3.11/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 gym_examples not found. Have you installed the proper package for gym_examples?

environment.txt

Code example

import gymnasium
import gym_examples
env = gymnasium.make('gym_examples/GridWorld-v0')

System info

Gymnasium installed using pip

Additional context

No response

Checklist

pseudo-rnd-thoughts commented 1 year ago

Hey, thanks for raising the issue. I think the issue is that the tutorial still uses gym and should be using gymnasium. If you replace import gym with import gymnasium as gym does this fix the issues ?

jlsvane commented 1 year ago

Hi Mark,

Thanks - it works. Two files need correction: in the gridworld file itself as well as in the the init file where the registration takes place.

BR

Jorgen

pseudo-rnd-thoughts commented 12 months ago

We have updated the environment creation tutorial so this should no longer be an issue

elmbeech commented 7 months ago

The error still occurs and cannot be fixed via pull request because: https://github.com/Farama-Foundation/gym-examples is no longer maintained and archived.

However, https://github.com/Farama-Foundation/gym-examples is used in the current documentation here: https://gymnasium.farama.org/tutorials/gymnasium_basics/environment_creation

As Jorgen @jlsvane mentioned, two files would have to be fixed:

  1. gym_examples/__init__.py

    #from gym.envs.registration import register                                     
    from gymnasium.envs.registration import register                                
  2. gym_examples/envs/grid_world.py

    #import gym                                                                     
    #from gym import spaces                                                         
    import gymnasium as gym                                                         
    from gymnasium import spaces                                                    

    As a newcomer, trying to understand how to use the gymnasium library by going through the official documentation examples, it makes things hard when things break by design.

So please, someone who can fix this in the archived repo, please fix it. Thank you, Elmar

pseudo-rnd-thoughts commented 7 months ago

For the updated tutorials see https://gymnasium.farama.org/main/introduction/create_custom_env/ and a larger version - https://gymnasium.farama.org/main/tutorials/gymnasium_basics/environment_creation/

elmbeech commented 7 months ago

ah, I see. I am sorry. thank you, @pseudo-rnd-thoughts for the link to the recent version! this is very helpful.