Gym: error while creating custom gym env : No registered env with id: Env-v4

Created on 3 Mar 2020  路  10Comments  路  Source: openai/gym

gym.make('Env-v4') is the command, the error is
Traceback (most recent call last):
File "C:\Python\Python38lib\site-packages\gym\envs\registration.py", line 118, in spec
return self.env_specs[id]
KeyError: 'Env-v4'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "C:\Python\Python38lib\site-packages\gym\envs\registration.py", line 142, in make
return registry.make(id, **kwargs)
File "C:\Python\Python38lib\site-packages\gym\envs\registration.py", line 86, in make
spec = self.spec(path)
File "C:\Python\Python38lib\site-packages\gym\envs\registration.py", line 128, in spec
raise error.UnregisteredEnv('No registered env with id: {}'.format(id))
gym.error.UnregisteredEnv: No registered env with id: Env-v4

custom_env.py is import gym
class CustomEnv(gym.Env):
def __init__(self):
print('Environment initialized')
def step(self):
print('Step successful!')
def reset(self):
print('Environment reset')
two init.py are
from envs.custom_env_dir.custom_env import CustomEnv
and
from gym.envs.registration import register
register(id='Env-v4',
entry_point='envs.custom_env_dir:CustomEnv',
tags={'wrapper_config.TimeLimit.max_episode_steps': 200},
reward_threshold=8, # optimum = 8.46
)

after pip install -e . i called import gym, import envs, env=gym.make('Env-v4')

What is the error here
what is the reason of error

Most helpful comment

Just to let you know (despite making myself look stupid) my issue was that my init.py files had single underscores either side instead of double so they weren't running ...... just on the off-chance you've done the same

All 10 comments

Having the same problem and tried everything in all the comments of the associated issues, must be missing something small. Grateful of any help

Just to let you know (despite making myself look stupid) my issue was that my init.py files had single underscores either side instead of double so they weren't running ...... just on the off-chance you've done the same

that worked. please dont call me stupid :). thanks by the way
To add, We need to delete egg.info folder too or do a pip uninstall Env-v4

Thanks for answering this @kirstenrichardson!

Hello, I still have the issue although my init files have double _.

What I did to register my environment was ok, I think. Running the pip3 install -e . command told me that my env was added. However, if I import gym and from gym import envs and print them all, mine isn't present.

Now, I don't understand how to run the training because I'm quite new to it. However, I'd need to run the HER algorithm + DDPG on my environment and I'd do so by saying python3 -m baselines.run --alg=her --env=Reach-v0 --num_timesteps=5000.

The baselines folder is in the same directory as the folder that contains the init files and .py files of my env. So in that directory I try to run that command from terminal but it exits with gym.error.UnregisteredEnv: No registered env with id: Reach-v0.

Maybe running the algorithm somehow after importing that environment folder would fix the issue? But how can I say import Reach and then python3... if I import inside python3 itself

When I use my custom environment with Stable Baselines the env ID has to be in the format 'gym_envname:envname-version' so perhaps 'gym_Reach:Reach-v0' in your case. That might not be the solution to your problem, there may be something else amiss there, but worth a try.

Thank you for the advice, I will try it.

However, I am trying to make things work for a previous repository from which I took the gym setup and the folder isn't called like that. The creators of the repository aren't answering unfortunately.

Hello,

I have tried that, but it doesn't work, still. Is there anyway I can find an implementation of HER + DDPG to train my environment that doesn't rely on the "python3 -m ..." command and run.py file?

I mean, stable-baselines has implementations of the single algorithms that are explained and you can write a script and manage your imports. I can't find a similar thing for the original baselines... Is it only done through that command?
I need to use baselines.

Best regards

I just solved a similar issue, I'd forgotten to import my custom env module at the top of the script.

I just solved a similar issue, I'd forgotten to import my custom env module at the top of the script.

Yeah, that worked for me too! I forgot this post. Must import everything in every main file of the libraries

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Baichenjia picture Baichenjia  路  3Comments

RuofanKong picture RuofanKong  路  3Comments

Spiral-Galaxy picture Spiral-Galaxy  路  3Comments

julian-ramos picture julian-ramos  路  4Comments

RuofanKong picture RuofanKong  路  4Comments