ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# Error while using OpenAI Gym in ROS Noetic

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 start_training.py, I am getting below error:

/usr/lib/python3/dist-packages/requests/__init__.py:89: 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/start_training.py", line 29, in <module>
env = gym.make('MyCartPole-v0')
File "/usr/local/lib/python3.8/dist-packages/gym/envs/registration.py", line 669, in make
env = PassiveEnvChecker(env)
File "/usr/local/lib/python3.8/dist-packages/gym/wrappers/env_checker.py", line 24, in __init__
assert hasattr(
AssertionError: The environment must specify an observation space. https://www.gymlibrary.dev/content/environment_creation/

edit retag close merge delete

Sort by » oldest newest most voted

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

AssertionError: The environment must specify an observation space. https://www.gymlibrary.dev/content/en...

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 start_training.py 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.

more