Closed NghiaPhamttk27 closed 1 year ago
@NghiaPhamttk27 You closed this issue, is that because you solved the problem? I'm facing the same issue.
I followed the tutorial https://gymnasium.farama.org/tutorials/gymnasium_basics/environment_creation/ and installed the environment with pip install -e gym-examples
from outside the directory (I also installed with pip install -e .
in the directory to see if it works).
The installation is done successfully, but when I try to use it like:
import gymnasium
env = gymnasium.make('gym_examples/GridWorld-v0')
it gives the error:
gymnasium.error.NamespaceNotFound: Namespace gym_examples not found. Have you installed the proper package for gym_examples?
I tried to call import gym_examples
to see if it does any difference, but the error persists.
There's an issue about this at https://github.com/Farama-Foundation/gym-examples/issues/16, but it says that gym
is not supported anymore and to use this repository (the funny thing is that the gymnasium tutorial recommends at the beginning to clone the gym-examples
repository that uses the gym
package, perhaps because it wasn't updated yet, or never will because it's archived now).
Anyway, I changed imports from gym
to gymnasium
, and gym
to gymnasium
in setup.py
to see if it solves the issue, but to no avail.
Update
I had forgotten to update the init file gym_examples\__init__.py
, changing the import from from gym.envs.registration import register
to from gymnasium.envs.registration import register
.
Then I installed the environment locally with pip install -e .
Now it works:
import gymnasium
env = gymnasium.make('gym_examples/GridWorld-v0')
print('env: ', env)
(there is no need to import gym_examples
, as it's not explicitly used)
@lucasbasquerotto Thanks, I also had this issue, following the custom environment tutorial: https://gymnasium.farama.org/tutorials/gymnasium_basics/environment_creation/#make-your-own-custom-environment
After git clone https://github.com/Farama-Foundation/gym-examples
:
In setup.py and grid_world.py:
Changing all mention of "gym" to "gymnasium" did the trick for me. (Or import gymnasium as gym.) Then:
cd gym-examples
py setup.py install
pip install -e .
And viola. It works. Simple example:
import gym_examples
def make_env(name="LunarLander-v2", render_mode="human"):
env = gym.make(name, render_mode=render_mode)
print('env: ', env)
observation, info = env.reset()
for _ in range(1000):
action = env.action_space.sample() # agent policy that uses the observation and info
observation, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
observation, info = env.reset()
env.close()
if __name__ == '__main__':
make_env(name="gym_examples/GridWorld-v0")
Describe the bug
I've followed https://gymnasium.farama.org/tutorials/gymnasium_basics/environment_creation/#creating-a-package. I have successfully registered the environment, but when I try to use that environment, I receive the error mentioned in the title. I have seen a similar issue here (https://github.com/Farama-Foundation/Gymnasium/issues/400), but all of my code is using Gymnasium (you can see it on my GitHub). Did I do something wrong? If so, please help me.
My github code: https://github.com/NghiaPhamttk27/GridWorld/tree/main
Code example
No response
System info
No response
Additional context
No response
Checklist