Hello, I am a beginner of open ai gym.
I want to add my environment, but I cannot do well.
Could someone tell me how to make new environment?
https://github.com/openai/gym/wiki/Environments
I did it along this wiki, and I run random_agent.py(replace CartPole-v0 to MyEnv-v0)
(ml_env_2)S-no-MacBook-Air-2:agents $ python random_agent.py
[2017-06-18 17:27:44,978] Making new env: MyEnv-v0
Traceback (most recent call last):
File "random_agent.py", line 36, in
env = gym.make(args.env_id)
File "/Users/S/.pyenv/versions/miniconda3-latest/envs/ml_env_2/lib/python2.7/site-packages/gym/envs/registration.py", line 161, in make
return registry.make(id)
File "/Users/S/.pyenv/versions/miniconda3-latest/envs/ml_env_2/lib/python2.7/site-packages/gym/envs/registration.py", line 118, in make
spec = self.spec(id)
File "/Users/S/.pyenv/versions/miniconda3-latest/envs/ml_env_2/lib/python2.7/site-packages/gym/envs/registration.py", line 147, in spec
raise error.UnregisteredEnv('No registered env with id: {}'.format(id))
gym.error.UnregisteredEnv: No registered env with id: MyEnv-v0
same problem
The question is how to register your own environment in the registry?
Lets say you have your own environment defined in the following structure:
myenv/
__init__.py
myenv.py
myenv.py contains the class for your environment. In __init__.py you put the following code:
from gym.envs.registration import register
register(
id='MyEnv-v0',
entry_point='myenv.myenv:MyEnv',
)
To use your own environment
import gym
import myenv
env = gym.make('MyEnv-v0')
More detailed example on how to register your own environments have a look here: https://github.com/openai/gym/blob/522c2c532293399920743265d9bc761ed18eadb3/gym/envs/__init__.py
NOTE: You have to have myenv directory in your PYTHONPATH or start python from the parent directory.
See also on StackOverflow: Is it possible to create a new gym environment in OpenAI?
@lilyxoxo - did this solve it for you? I create my own enviroments and could knock up a sample git repro if you are still stuck
@Sohojoe That would be great. Even though the question is asked quite poorly there are probably a few others looking for something like this to help them make their own environment.
@Sohojoe I apologize for this late reply.
I have already solved this problem.
Thank you.
@lily-xoxo-30 could you maybe share your solution or give a quick how to? I’m also struggling with this problem now for a while already.
@peterlabuschagne Did you have a look at https://stackoverflow.com/a/47132897/562769 ? What else do you need?
I’m trying to build my self a A.i so I’m sure my is going right and on time
On Mon, Dec 11, 2017 at 5:04 AM Cristyan David cristyandavid1@gmail.com
wrote:
On Sun, Dec 10, 2017 at 8:34 AM Martin Thoma notifications@github.com
wrote:@peterlabuschagne https://github.com/peterlabuschagne Did you have a
look at https://stackoverflow.com/a/47132897/562769 ? What else do you
need?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/openai/gym/issues/626#issuecomment-350548782, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AeF0C3qB17wnVTqOnDOZWUb_w7i748JGks5s-93ZgaJpZM4N9cPf
.
@MartinThoma no I hadn't yet seen that, but that really answers the questions I've had up until now. Hopefully the rest is smooth sailing. Thanks a lot!
Thanks for answering this @hholst80! Please see the documentation here: https://github.com/openai/gym/blob/master/docs/creating-environments.md
What fixed this for me was prefixing foo-v0 in the following line with gym_foo: as below:
gym.make('gym_foo:foo-v0')
Most helpful comment
The question is how to register your own environment in the registry?
Lets say you have your own environment defined in the following structure:
myenv.pycontains the class for your environment. In__init__.pyyou put the following code:To use your own environment
More detailed example on how to register your own environments have a look here: https://github.com/openai/gym/blob/522c2c532293399920743265d9bc761ed18eadb3/gym/envs/__init__.py
NOTE: You have to have
myenvdirectory in your PYTHONPATH or start python from the parent directory.