ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Error while using OpenAI Gym in ROS Noetic

asked 2022-10-24 15:42:22 -0500

jandisoon gravatar image

updated 2022-10-26 04:45:38 -0500

ravijoshi gravatar image

I have installed OpenAI Gym and ROS Noetic. Now, I'm following this tutorial in YouTube in my local installation. However, after executing the following command rosrun cartpole_v0_training, I am getting below error:

/usr/lib/python3/dist-packages/requests/ RequestsDependencyWarning: urllib3 (1.26.12) or chardet (3.0.4) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
  File "/home/zahra/openai_ws/src/cartpole_v0_training/scripts/", line 29, in <module>
    env = gym.make('MyCartPole-v0')
  File "/usr/local/lib/python3.8/dist-packages/gym/envs/", line 669, in make
    env = PassiveEnvChecker(env)
  File "/usr/local/lib/python3.8/dist-packages/gym/wrappers/", line 24, in __init__
    assert hasattr(
AssertionError: The environment must specify an observation space.
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-10-26 04:44:55 -0500

ravijoshi gravatar image

Below, I am quoting the error from logs posted in the question:

AssertionError: The environment must specify an observation space.

The above error is unrelated to ROS. It is coming from OpenAI Gym.

There are certain rules that must be followed when designing a new environment in OpenAI Gym. For example, every environment must have observation space. The observation space is defined by the observation_space attribute. However, it is not specified in your case, i.e., env.observation_space in None. Thus you are getting the error.

Please change line number 29 of the file, where you are creating an environment, with the following:

env = gym.make('CartPole-v0')

Notice that I am using an existing environment in OpenAI Gym.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2022-10-24 15:42:22 -0500

Seen: 93 times

Last updated: Oct 26 '22