Exercise 2.3: ImportError: 'module' object has no attribute 'CartPoleStayUpEnv'

After following the instructions step-by-step and running:

roslaunch my_cartpole_training start_training.launch

, I am receiving this error:

ROS_MASTER_URI=http://master:11311

process[cartpole_gym-1]: started with pid [17866]
/usr/local/lib/python2.7/dist-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.25.8) or chardet (2.3.0) doesn't match a supported version!
  RequestsDependencyWarning)
/usr/local/lib/python2.7/dist-packages/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
Traceback (most recent call last):
  File "/home/user/my_cartpole_training/src/start_qlearn.py", line 24, in <module>
    env = gym.make('CartPoleStayUp-v1')
  File "/usr/local/lib/python2.7/dist-packages/gym/envs/registration.py", line 161, in make
    return registry.make(id)
  File "/usr/local/lib/python2.7/dist-packages/gym/envs/registration.py", line 119, in make
    env = spec.make()
  File "/usr/local/lib/python2.7/dist-packages/gym/envs/registration.py", line 85, in make
    cls = load(self._entry_point)
  File "/usr/local/lib/python2.7/dist-packages/gym/envs/registration.py", line 17, in load
    result = entry_point.load(False)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2229, in load
    return self.resolve()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2239, in resolve
    raise ImportError(str(exc))
ImportError: 'module' object has no attribute 'CartPoleStayUpEnv'
[cartpole_gym-1] process has died [pid 17866, exit code 1, cmd /home/user/my_cartpole_training/src/start_qlearn.py __name:=cartpole_gym __log:=/home/user/.ros/log/58da97f2-6adc-11ea-8bb0-16ab3dc29d7b/cartpole_gym-1.log].
log file: /home/user/.ros/log/58da97f2-6adc-11ea-8bb0-16ab3dc29d7b/cartpole_gym-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done

Is this class present in the file, where your

'CartPoleStayUp-v1'

gym environment is defined?

Yep here are the steps I took:

  1. Copied stay_up.py to src/my_cartpole_task_env.py
  2. vim my_cartpole_task_env.py
  3. :%s/v0/v1/g :wq # replaced all occurrences of “v0” to “v1”
  4. vim start_training.py
  5. Changed from openai_ros.task_envs.cartpole_stay_up import stay_up to from my_cartpole_task_env import stay_up
  6. Also tried from openai_ros.task_envs.cartpole_stay_up import stay_up to import my_cartpole_task_env
  7. :%s/v0/v1/g :wq
  8. roslaunch my_cartpole_training start_training.launch

Does your file ‘my_cartpole_task_env’ have the correct entry point? This should be what causes the error.

I had the same problem and I solved by changing the entry point from ‘openai_ros:CartPoleStayUpEnv’ to ‘my_cartpole_task_env:CartPoleStayUpEnv’

Thanks that solved the issue.